Search All of the Math Forum:

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

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Help with ODE Problem
Replies: 7   Last Post: Jul 23, 2013 12:35 AM

 Messages: [ Previous | Next ]
 Marc Posts: 108 Registered: 7/2/10
Re: Help with ODE Problem
Posted: Jul 15, 2013 10:38 PM

"Lauara " <osornol@fiu.edu> wrote in message <ks13gl\$pmk\$1@newscl01ah.mathworks.com>...
> "Jan Simon" wrote in message <ks0q2f\$rla\$1@newscl01ah.mathworks.com>...
> > Dear Lauara,
> >
> > Follow the standard approach directly:
> >

> > > Mx??+Cx?+Kx=P(t)
> > > x'' = inv(M) * (P(t) - Cx' -Kx)

> >
> > Lookup table: y1 = x, y2 = x', y3 = x''
> >
> > dydt(1) = y(2);
> > dydt(2) = (P(t) - C * y(2) - K * y(1)) \ M;
> >
> > Or you could expand M to work with the vector y.
> >
> > Kind regards, Jan

>
> Thank you so much Jan for your response. I have written the code as you said:
>
> tspan=[0 0.25 0.5];
> y0=zeros(76,1);
> yp0=zeros(76,1);
> [T,Y]=ode15i(@(t,y) Differential_Equation_Solver(t,y,K,M,C,P),tspan,y0,yp0);
>
> %%%%%%%
>
> function dydt=Differential_Equation_Solver(t,y,K,M,C,P)
> dydt(1) = y(2);
> dydt(2) = M\(P-C*y(2)-K*y(1));
> end
>
> But I am still getting an error for the number of the input arguments:
>
> Too many input arguments.
>
> Error in odearguments (line 88)
> f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
>
> Error in ode15i (line 117)
> [neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, ~, odeFcn, ...
>
> Error in Bridge_Displacement (line 49)
> [T,Y]=ode15i(@(t,y) Differential_Equation_Solver(t,y,K,M,C,P),tspan,y0,yp0);
>
> why do you think this format is wrong and how should I fix it?
>
> Again, Thank you very much for your useful tip.

You can not pass the K,M,C,P variables into the solver. See "nested functions" or the documentation on "passing other variables into functions" with the Matlab ODE solvers.

Also, make sure your ode function is spitting on a column vector.

Using the call to dydt = zeros(2,1); before the equations will fix that.

So, your function needs to look like this.....

function dydt = yourODE(t,y)

K = ....
M = ....
etc. etc.

dydt = zeros(2,1);
etc.etc.

end

Try hard coding the variables first, then look into using a nested function.

Date Subject Author
7/12/13 Lauara
7/15/13 Jan Simon
7/15/13 Lauara
7/15/13 Marc
7/21/13 Jan Simon
7/22/13 Torsten
7/23/13 Marc
7/16/13 Torsten