Plots

조회 수: 14 (최근 30일)
Francis Mboya
Francis Mboya 2011년 4월 14일
Is there a way to make the plot wave move through the domain til x=1?
freq = 1; % Hz
omega = 2*pi*freq; % angular speed m/s
c = 10; % m/s
amp = 1;
% Space
dx = 0.001;
xmax = 1; % domain of unit length
lambda = 0.05; % size of wave
k = 2*pi/lambda; % wavenumber
x = 0:dx:xmax;
Vx = length(x); % matrix of propagation in the x direction
u_0 = zeros(size(x));
% defining wave initial conditions
for i = 1:Vx;
if x(i) < lambda;
u_0(i) = (1 - cos(k*x(i)))*0.5;
else
break
end
end
%Time
dt = 0.01;
t = 0:dt:1;
Vt = length(t);
phi = zeros(Vx,Vt);
for n = 1:Vx;
phi(1,i) = u_0(i);
phi(2,i) = u_0(i);
end
for i = 2:Vt
for n = 2:Vx-1
phi(i,n+1) = phi(i,n-1) + (u_0(i)*(dt/dx))*(phi(i+1,n) - phi(i-1,n)/phi(i,n-1));
end
end
figure(1)
plot(x,u_0,'.-b');
axis([0 1 0 1])
  댓글 수: 1
Francis Mboya
Francis Mboya 2011년 4월 14일
preferably using the scheme (phi)

댓글을 달려면 로그인하십시오.

채택된 답변

Laura Proctor
Laura Proctor 2011년 4월 14일
If you add the following block of code to the end, it will show the wave propagating along the x-axis, but I don't think this is exactly what you envision - particularly since the variable PHI seems to be defined, but not used in the plot. I would imagine that defining a 2-dimensional variable where each column represents the amplitude at a time step and each row gives the amplitude of a specific x-location over time would be useful.
while u_0(end)==0
u_0 = [ u_0(end-5:end) u_0(1:end-6) ];
plot(x,u_0,'.-b');
pause(0.05)
end
  댓글 수: 2
Francis Mboya
Francis Mboya 2011년 4월 14일
that is the problem i am having. I would like to use phi (leap frog scheme) to propagate along x and make it behave the same way. How do i define that in te plot script, thanks?
Laura Proctor
Laura Proctor 2011년 4월 14일
I'm not entirely sure without knowing the equations. It seems like you're trying to perform some numerical analysis, but I'm just not sure of the equations.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by