Borrar filtros
Borrar filtros

Odesolver using a vector instead a function

1 visualización (últimos 30 días)
Jose
Jose el 8 de Sept. de 2012
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 comentario
Jose
Jose el 9 de Sept. de 2012
I tried to add two differencial equations inside the dfun:
f2=??? ─────────↓
dfun=inline('[1,f2,dery(f(2))]','t','f','dery');
So the output for:
y0=initial value for y @ t=0
[t,y]=ode45(@(t,f) dfun(t,f,dery),t,[a,9999999,y0],...
odeset('Mass',[1 0 0;0 0 0;0 0 1]));
y(:,1)
Will be:
[a;a+t(1)-t(2);a+t(1)-t(3);a+t(1)-t(4);...];
Assumming the diference between the values t(n)-t(n+1)is constant for all the values on the vector t, we can choose the value for 'a' to be this same difference, so:
y(:,1)=[a;2a;3a;4a;...];
Using:
f2=f(1)/a
Will create the vector:
y(:,2)=[1;2;3;4;...];
That can be used as index numbers to get the scalar values from dery, my problem is the time vector have not constant differences, any idea?

Iniciar sesión para comentar.

Respuestas (1)

Jan
Jan el 9 de Sept. de 2012
Editada: Jan el 9 de Sept. de 2012
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.

Categorías

Más información sobre Ordinary Differential Equations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by