Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Help with ode45
Replies: 3   Last Post: Oct 17, 2012 9:46 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
pietro

Posts: 374
Registered: 1/3/09
Re: Help with ode45
Posted: Oct 17, 2012 3:43 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Anna Baturin" <anna_baturin@student.uml.edu> wrote in message <k5ks35$56m$1@newscl01ah.mathworks.com>...
> I am trying to use the ode45 function for dy/dx=sin(y*x^2)
> the function was saved as an m file which I called f
> I have to do it for y0=2 and y0=1 and then plot them.
> When I plot I keep getting the error "vectors must be the smae length"
> Here is my work:
> a=-2
> b=2
> y0=2
> y01=1
> [x,y1]=ode45('f',[a,b],y0)
> [x,y2]=ode45('f',[a,b],y01)
> plot(x,y1,'--k',x,y2)
> then I get the error "vectors muct be the smae length"
> How do I fix this?


try this:

function dy = myfun(x,y)
dy = zeros(2,1); % a column vector
dy(1) = y(2);
dy(2) = sin(y*x^2);

[x,y1]=ode45(@myfun,[a,b],y0)



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.