Marc
Posts:
108
Registered:
7/2/10


Re: Help with ODE Problem
Posted:
Jul 23, 2013 12:35 AM


"Torsten" wrote in message <ksil62$k9p$1@newscl01ah.mathworks.com>... > "Jan Simon" wrote in message <kshjrc$b7g$1@newscl01ah.mathworks.com>... > > Dear Marc, > > > > > > [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\(PC*y(2)K*y(1)); > > > > end > > > > > > > > > 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. > > > > It is valid and recommended to pass constants by using anonymous functions, see: > > http://www.mathworks.com/matlabcentral/answers/1971 > > > > The problem is the yp0. This is another method to pass constants to the function to be integrated. But the function Differential_Equation_Solver does not accept further parameters in the inputs. So omitting yp0 as input to ODE45 should solve the problem, as mentioned above. > > > > Kind regards, Jan > > Two further errors in the code: > 1. The OP tries to solve 152 ODEs, not only 2 as implied by the function Differential_Equation_Solver. > 2. For ODE15i, you will have to supply residuals, not time derivatives. > > Best wishes > Torsten.
Yeah, this threw me off. I missed the anonymous function call.

