ODE with a parameter that chages at each time step

Hi all,
I have a problem solving a ODE with Matlab.
The ODE is:
y(t)'of j= [(sigma^2)/(2*k)]*(1-y(t)*k)*(y(t)-[y(t)of j-1])^2;
I've written this code:
mu = 0.20;
r = 0.05;
sigma = 0.40;
T = 10;
k = 0.2;
IC = 0.0;
TSPAN = 0:0.1:T;
TSPANlength = length(TSPAN);
%Number of crahes
N=3;
PiVektor = zeros(N,TSPANlength);
for i=1:1:N
[~, PiVektor(i, :)] = ode23(@(t, pi)myodeN(pi, PiVektor(i-1),k,mu,r,sigma),TSPAN, IC);
PiVektor(i,:) = fliplr(PiVektor(i,:));
figure(1);
hold on
plot(TSPAN,PiVektor(i,:));
end
function dpidt = myodeN(pi,piNminus1,k,mu,r,sigma)
dpidt = [(sigma^2)/(2*k)]*(1-pi*k)*(pi-piNminus1)^2;
end
The problem is that in this way the ODE is always calculated using just the first value from the previous calculation.
Is it possibile to change the value of my parameter at each time step?
Thanks a lot,
Ilaria

댓글 수: 2

I don't understand your notation. What does y(t)' of j mean?
ilaria
ilaria 2011년 9월 4일
y(t)' of j is the differential equation for the jth crash. With an example i think that it could be clearer:
differential equation 1 crash:
y'(t)= [0.4^2/0.2*2]*(1-0.2y(t))*(y(t)- VALUE_OF_Y_FOR_0CRASH_AT_TIME_t]^2
differential equation 2 crashes:
y'(t)= [0.4^2/0.2*2]*(1-0.2y(t))*(y(t)- VALUE_OF_Y_FOR_1CRASH_AT_TIME_t]^2

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

 채택된 답변

Bjorn Gustavsson
Bjorn Gustavsson 2011년 9월 7일

1 개 추천

So you will have a sequence of ODEs to solve starting with the one for 0-crashes and then you want to plug in that solution into the solution for the 1-crash ODE?
If so I would call the ode-solver with
[tOut{i}, pOut{i}] = ode23(@(t, pi)myodeN(t,pi,{tOut{i-1},pOut{i-1},k,mu,r,sigma),TSPAN, IC);
and then modify your myodeN to something like this:
function dpidt = myodeN(t,pi,TnPprev,k,mu,r,sigma)
dpidt = [(sigma^2)/(2*k)]*(1-pi*k)*(pi-interp1(TnPprev{1},TnPprev{2},t))^2;
That way you interpolate a value for piNminus1 for times t from the "piNminus1" values (that you have values for at the choosen times). You could also use the single-output format of ode-solvers and then instead of explicitly interpolating use deval to calculate the values of piNminus1 for any given time.
HTH

추가 답변 (2개)

Grzegorz Knor
Grzegorz Knor 2011년 9월 4일

0 개 추천

Did you mean delay differential equations?
doc dde23
ilaria
ilaria 2011년 9월 7일

0 개 추천

No, i think that this type of differential equation is not a d.d.e. I'm not sure but I think that ode23 is not able to solve this type of problem.. what do you think?

카테고리

태그

Community Treasure Hunt

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

Start Hunting!

Translated by