pietro
Posts:
374
Registered:
1/3/09


Re: Help with ode45
Posted:
Oct 17, 2012 3:43 AM


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

