matlab - 3d plot of wave function -
how can plot wave function n=a*cos(k*x-w*t)
in matlab in 3d simulation? code used was:
k=0.05; f=100; w=2*pi*f; a=1; x=[-5:1:5]; t=[0:2:20]; n=a.*cos(k.*x-w.*t); surf(x,t,n);
to plot surface need mesh of data. x,t
created line, there single t
every x
, surface has multiple t
every x
.
if change definition of x
, t
to:
[x,t]=meshgrid(-5:1:5,0:2:20);
your code runs , plots:
Comments
Post a Comment