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