Plots
14 次查看(过去 30 天)
显示 更早的评论
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])
采纳的回答
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 个评论
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!