Graphing of Partial Differential Equation

2 views (last 30 days)
My code is simple and as a below:
d=0.25*log(1.75); e=d/(sqrt(4*(pi()^2)+d^2)); wd=16*pi(); wn=wd/sqrt(1-e^2); x0=1.75; t=0:0.1:2; x=x0*exp(-e*wn*t)*(cos(wd*t)+(e*wn/wd)*sin(wd*t)); plot(t,x)
For some reason the function isn't getting plotted i get an undefined error in the 7th line. The funny thing is when i replace the "*" before the cos, with a "+" the code seems to work and I get a graph. I can't figure what the problem is here. Help will be much appreciated this is my first post so apologies for any mistakes/inconveniences. Thanks in advance

Accepted Answer

the cyclist
the cyclist on 16 Mar 2011
The code as written is attempting a matrix multiplication, but you presumably want element-by-element. Add a dot before the multiplication:
x=x0*exp(-e*wn*t).*(cos(wd*t)+(e*wn/wd)*sin(wd*t));

More Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!