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.

 採用された回答

Paulo Silva
Paulo Silva 2011 年 2 月 28 日

1 投票

"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 件のコメント

Matt
Matt 2011 年 2 月 28 日
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 ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by