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 breakendend%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); endfor 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)); endend figure(1)plot(x,u_0,'.-b');axis([0 1 0 1])
MATLAB: Plots
dot
Best Answer