Odesolver using a vector instead a function
Mostra commenti meno recenti
Hi
Be y(t) a function and y'(t) his derivate.
I have two vectors, the first containing the values for time and the second containing the values for y'(t) evaluated at the data on vector time (hence, both vector have the same size).
Normally when I use an odesolver, I write a function containing the symbolic derivate for y(t), and then calculate the value for y(t) using something like this:
t=[0;12;40;87;122;147;181;232;260;300; ...]
k=[6 5 4];
dfun=inline('(k(1)/k(2)+k(3)','t','f','k');
[t,y]=ode45(@(t,f) dfun(t,f,k),t,0);
My problem come since I have a vector being y'(t) instead a function. Tried to do the next:
t=[0;12;40;87;122;147;181;232;260;300; ...]
dery=[0;0.002;0.01;0.02;0.05;0.1;0.2;0.35; ...]
dfun=inline('dery','t','f','dery');
[t,y]=ode45(@(t,f) dfun(t,f,dery),t,0);
This give me the next error:
??? Error using ==> odearguments at 116
Solving @(T,F)DFUN(T,F,DERY) requires an initial condition vector of
length 1.
Error in ==> ode45 at 173
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
Error in ==> poly at 153
[t,y]=ode45(@(t,f) dfun(t,f,dery),t,0);
The difference between the first and second code is, I use scalars on the calculation for the first ( k(1), k(2), k(3) ), but for the second I have the vector dery.
How this can be solved? Thanks
1 Commento
Jose
il 9 Set 2012
Risposte (1)
The integration of data provides as a vector instead of a function is solved by trapz. A step-size controlled ODE solver is not sufficient for such calculations.
Unfortunately trapz cannot use the derivatives, but only the values.
Categorie
Scopri di più su Programming in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!