Plots

14 views (last 30 days)
Francis Mboya
Francis Mboya on 14 Apr 2011
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 Comment
Francis Mboya
Francis Mboya on 14 Apr 2011
preferably using the scheme (phi)

Sign in to comment.

Accepted Answer

Laura Proctor
Laura Proctor on 14 Apr 2011
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 Comments
Francis Mboya
Francis Mboya on 14 Apr 2011
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 on 14 Apr 2011
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.

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!