Undefined variable problem in a simple model for non-linear oscillator

Hey guys, I'm just trying to run a very simple function to help model a non-linear oscillator. Here's the code:
function vp=F(t,v);
vp=zeros(2,1);
vp(1)=v(2);
vp(2)= -(v(2)+v(1)+3*(v(1))^3)+20*cos(w*t);
I had to transform it into a 1st order eq b/c it seems like matlab can't handle second order equations for some reason. When I type in the following, I get an error saying "undefined function or variable 't'"
%[t,v]=ode45('F',[0,15],[0,0])
plot(t,v(:,1))
I'm not experienced with MatLab at all! Any help would be greatly appreciated.

 采纳的回答

"When I type in the following, I get an error saying "undefined function or variable 't'"
%[t,v]=ode45('F',[0,15],[0,0])
plot(t,v(:,1))"
You commented the line where the t was created therefore there's no t and matlab gives you that error

1 个评论

Wow duh! This is what happens when you don't pay attention and neglect sleep. I feel pretty dumb now, but thank you for saving me from going on a witch hunt for that seemingly elusive error. Much appreciated!

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by