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:

enter image description here


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -