필터 지우기
필터 지우기

Odesolver using a vector instead a function

조회 수: 1 (최근 30일)
Jose
Jose 2012년 9월 8일
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
Jose
Jose 2012년 9월 9일
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?

댓글을 달려면 로그인하십시오.

답변 (1개)

Jan
Jan 2012년 9월 9일
편집: Jan 2012년 9월 9일
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.

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by