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.

 Réponse acceptée

Paulo Silva
Paulo Silva le 28 Fév 2011
"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 commentaire

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!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Programming dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by