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.

 Accepted Answer

"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 Comment

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!

Sign in to comment.

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Asked:

on 28 Feb 2011

Community Treasure Hunt

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

Start Hunting!