Prev: SBML support in SimBiology
Next: Read a *. File
From: Adam Jacob on 11 Apr 2008 17:54 Hello.. wondering if anyone can help out. I'm trying to solve an ode final value problem. So for e.g. solving dydt=f(y,t) for t0 (initial time) to tfinal (final time) with y(tfinal)=yf. I tried solving backwards in time using tspan = LINSPACE(tf1,t01); ode45(@(t,Y) odefun(t,Y,vars),tspan,yf); So my timespan is backwards. I got a very bad solution (very large) but when I solved it as an initial value problem tspan = LINSPACE(t01,tf1); ode45(@(t,Y) odefun(t,Y,vars),tspan,yf); The solution seemed reasonable. Just wondering if I "flipped" the result of the initial value problem, does that make it a valid final value problem? Wondering how ode45 solves backwards in time (when tspan has decreasing values). Any help at all would be appreciated.. Adam
From: Yi Cao on 12 Apr 2008 10:28 "Adam Jacob" <ajacob73(a)yahoo.com> wrote in message <ftomlp$d4q$1(a)fred.mathworks.com>... > Hello.. wondering if anyone can help out. > I'm trying to solve an ode final value problem. So for e.g. > solving dydt=f(y,t) for t0 (initial time) to tfinal (final > time) with y(tfinal)=yf. > I tried solving backwards in time using > > tspan = LINSPACE(tf1,t01); > ode45(@(t,Y) odefun(t,Y,vars),tspan,yf); > > So my timespan is backwards. I got a very bad solution > (very large) but when I solved it as an initial value > problem > > tspan = LINSPACE(t01,tf1); > ode45(@(t,Y) odefun(t,Y,vars),tspan,yf); > > The solution seemed reasonable. > Just wondering if I "flipped" the result of the initial > value problem, does that make it a valid final value > problem? Wondering how ode45 solves backwards in time (when > tspan has decreasing values). > > Any help at all would be appreciated.. > Adam It may be because of your odefun. Could you post your odefun here? Yi Cao
From: Adam Jacob on 13 Apr 2008 12:59 Thanks Yi... I'll put in the whole m-script so that if you run it you can see what I mean... if I switch tf and t0 in tspan (so ODE45 is solving an initial value problem forwards in time) than it gets a somewhat reasonable solution than backwards in time. Not sure since if I do that with other functions I get the same result (backwards in time ODE45 solution is the same as forwards in time ODE45 solution but reversed in time)... Thanks, Adam %-----MAIN M-FILE-------------- clear all %-----VARIABLE SET-UP-------------- brakestep=1; brakestart=1; brakerelease=11; exptime=30; c=0.1; g=9.81; A = [0 1 0 0 0; 0 0 -g 0 1; 0 0 0 1 0; 0 0 0 -1/c 0;0 0 0 0 -20]; B = [0; 0; 0; 1/c; 0]; R = 10; Q = [1 0 0 0 0; 0 0 0 0 0; 0 0 0 0 0; 0 0 0 0 0;0 0 0 0 0]; S = [0; 0; 0; 0; 0]; E = eye(5); dps=70; stepnum=dps*exptime I5=eye(5) %-----TO RUN and PLOT ODE SOLUTION-------------- t01= 0; tf1=exptime; tspan1 = LINSPACE(tf1,t01,dps*(tf1-t01)); X01=zeros(5); [Time1,X1] = ode45(@(t,X) odefuncare2 (t,X,A,B,Q,R,S,E),tspan1,X01); plot(Time1,X1) %-------ODEFUNCTION------------------ function dxdt = odefuncare(t,X,A,B,Q,R,S,E) X = reshape(X,5,5); %converting X from a column vector generated by ode45 into a 5 x 5 Matrix dxdt=((A')*X*E)+((E')*X*A)-(((E')*(X)*(B)+S)*(inv(R))*((B')* (X)*(E)+(S')))+Q; dxdt = dxdt(:); %converting dxdt into a column vector as expected by ode45 %-------END OF SCRIPT FILES-------- "Yi Cao" <y.cao(a)cranfield.ac.uk> wrote in message <ftqgth$4t6$1(a)fred.mathworks.com>... > "Adam Jacob" <ajacob73(a)yahoo.com> wrote in message > <ftomlp$d4q$1(a)fred.mathworks.com>... > > Hello.. wondering if anyone can help out. > > I'm trying to solve an ode final value problem. So for > e.g. > > solving dydt=f(y,t) for t0 (initial time) to tfinal > (final > > time) with y(tfinal)=yf. > > I tried solving backwards in time using > > > > tspan = LINSPACE(tf1,t01); > > ode45(@(t,Y) odefun(t,Y,vars),tspan,yf); > > > > So my timespan is backwards. I got a very bad solution > > (very large) but when I solved it as an initial value > > problem > > > > tspan = LINSPACE(t01,tf1); > > ode45(@(t,Y) odefun(t,Y,vars),tspan,yf); > > > > The solution seemed reasonable. > > Just wondering if I "flipped" the result of the initial > > value problem, does that make it a valid final value > > problem? Wondering how ode45 solves backwards in time > (when > > tspan has decreasing values). > > > > Any help at all would be appreciated.. > > Adam > > It may be because of your odefun. Could you post your > odefun here? > > Yi Cao
From: Yi Cao on 14 Apr 2008 10:56 "Adam Jacob" <ajacob73(a)yahoo.com> wrote in message <ftte4m$935$1(a)fred.mathworks.com>... > Thanks Yi... I'll put in the whole m-script so that if you > run it you can see what I mean... if I switch tf and t0 in > tspan (so ODE45 is solving an initial value problem > forwards in time) than it gets a somewhat reasonable > solution than backwards in time. Not sure since if I do > that with other functions I get the same result (backwards > in time ODE45 solution is the same as forwards in time > ODE45 solution but reversed in time)... > Thanks, > Adam > > %-----MAIN M-FILE-------------- > clear all > %-----VARIABLE SET-UP-------------- > brakestep=1; > brakestart=1; > brakerelease=11; > exptime=30; > c=0.1; > g=9.81; > A = [0 1 0 0 0; 0 0 -g 0 1; 0 0 0 1 0; 0 0 0 -1/c 0;0 0 0 > 0 -20]; > B = [0; 0; 0; 1/c; 0]; > R = 10; > Q = [1 0 0 0 0; 0 0 0 0 0; 0 0 0 0 0; 0 0 0 0 0;0 0 0 0 0]; > S = [0; 0; 0; 0; 0]; > E = eye(5); > dps=70; > stepnum=dps*exptime > I5=eye(5) > %-----TO RUN and PLOT ODE SOLUTION-------------- > t01= 0; > tf1=exptime; > tspan1 = LINSPACE(tf1,t01,dps*(tf1-t01)); > X01=zeros(5); > [Time1,X1] = ode45(@(t,X) odefuncare2 > (t,X,A,B,Q,R,S,E),tspan1,X01); > plot(Time1,X1) > %-------ODEFUNCTION------------------ > function dxdt = odefuncare(t,X,A,B,Q,R,S,E) > X = reshape(X,5,5); %converting X from a column vector > generated by ode45 into a 5 x 5 Matrix > dxdt=((A')*X*E)+((E')*X*A)-(((E')*(X)*(B)+S)*(inv(R))* ((B')* > (X)*(E)+(S')))+Q; > dxdt = dxdt(:); %converting dxdt into a column vector > as expected by ode45 > %-------END OF SCRIPT FILES-------- > > > > > "Yi Cao" <y.cao(a)cranfield.ac.uk> wrote in message > <ftqgth$4t6$1(a)fred.mathworks.com>... > > "Adam Jacob" <ajacob73(a)yahoo.com> wrote in message > > <ftomlp$d4q$1(a)fred.mathworks.com>... > > > Hello.. wondering if anyone can help out. > > > I'm trying to solve an ode final value problem. So for > > e.g. > > > solving dydt=f(y,t) for t0 (initial time) to tfinal > > (final > > > time) with y(tfinal)=yf. > > > I tried solving backwards in time using > > > > > > tspan = LINSPACE(tf1,t01); > > > ode45(@(t,Y) odefun(t,Y,vars),tspan,yf); > > > > > > So my timespan is backwards. I got a very bad solution > > > (very large) but when I solved it as an initial value > > > problem > > > > > > tspan = LINSPACE(t01,tf1); > > > ode45(@(t,Y) odefun(t,Y,vars),tspan,yf); > > > > > > The solution seemed reasonable. > > > Just wondering if I "flipped" the result of the initial > > > value problem, does that make it a valid final value > > > problem? Wondering how ode45 solves backwards in time > > (when > > > tspan has decreasing values). > > > > > > Any help at all would be appreciated.. > > > Adam > > > > It may be because of your odefun. Could you post your > > odefun here? > > > > Yi Cao > Dear Adma Now I know what is your problem. You want to integrate the differential Riccati equation in reverse time. The Riccati equation in reverse time is unstable. Hence, a small numerical error will eventually becomes infinite large. That is why you feel you result is strange. If you look the results in a short period, you will see this instability. Because your equation is not time varying, therefore, as you mentioned before, it is better to integrate in forward time, i.e. from [-30 0], then explain the results reversely. hth. Yi Cao
From: Adam Jacob on 17 Apr 2008 20:50 Thanks very much for the help Yi.. Adam "Yi Cao" <y.cao(a)cranfield.ac.uk> wrote in message <ftvra1 $8b3$1(a)fred.mathworks.com>... > "Adam Jacob" <ajacob73(a)yahoo.com> wrote in message > <ftte4m$935$1(a)fred.mathworks.com>... > > Thanks Yi... I'll put in the whole m-script so that if > you > > run it you can see what I mean... if I switch tf and t0 > in > > tspan (so ODE45 is solving an initial value problem > > forwards in time) than it gets a somewhat reasonable > > solution than backwards in time. Not sure since if I do > > that with other functions I get the same result > (backwards > > in time ODE45 solution is the same as forwards in time > > ODE45 solution but reversed in time)... > > Thanks, > > Adam > > > > %-----MAIN M-FILE-------------- > > clear all > > %-----VARIABLE SET-UP-------------- > > brakestep=1; > > brakestart=1; > > brakerelease=11; > > exptime=30; > > c=0.1; > > g=9.81; > > A = [0 1 0 0 0; 0 0 -g 0 1; 0 0 0 1 0; 0 0 0 -1/c 0;0 0 0 > > 0 -20]; > > B = [0; 0; 0; 1/c; 0]; > > R = 10; > > Q = [1 0 0 0 0; 0 0 0 0 0; 0 0 0 0 0; 0 0 0 0 0;0 0 0 0 > 0]; > > S = [0; 0; 0; 0; 0]; > > E = eye(5); > > dps=70; > > stepnum=dps*exptime > > I5=eye(5) > > %-----TO RUN and PLOT ODE SOLUTION-------------- > > t01= 0; > > tf1=exptime; > > tspan1 = LINSPACE(tf1,t01,dps*(tf1-t01)); > > X01=zeros(5); > > [Time1,X1] = ode45(@(t,X) odefuncare2 > > (t,X,A,B,Q,R,S,E),tspan1,X01); > > plot(Time1,X1) > > %-------ODEFUNCTION------------------ > > function dxdt = odefuncare(t,X,A,B,Q,R,S,E) > > X = reshape(X,5,5); %converting X from a column vector > > generated by ode45 into a 5 x 5 Matrix > > dxdt=((A')*X*E)+((E')*X*A)-(((E')*(X)*(B)+S)*(inv(R))* > ((B')* > > (X)*(E)+(S')))+Q; > > dxdt = dxdt(:); %converting dxdt into a column > vector > > as expected by ode45 > > %-------END OF SCRIPT FILES-------- > > > > > > > > > > "Yi Cao" <y.cao(a)cranfield.ac.uk> wrote in message > > <ftqgth$4t6$1(a)fred.mathworks.com>... > > > "Adam Jacob" <ajacob73(a)yahoo.com> wrote in message > > > <ftomlp$d4q$1(a)fred.mathworks.com>... > > > > Hello.. wondering if anyone can help out. > > > > I'm trying to solve an ode final value problem. So > for > > > e.g. > > > > solving dydt=f(y,t) for t0 (initial time) to tfinal > > > (final > > > > time) with y(tfinal)=yf. > > > > I tried solving backwards in time using > > > > > > > > tspan = LINSPACE(tf1,t01); > > > > ode45(@(t,Y) odefun(t,Y,vars),tspan,yf); > > > > > > > > So my timespan is backwards. I got a very bad > solution > > > > (very large) but when I solved it as an initial value > > > > problem > > > > > > > > tspan = LINSPACE(t01,tf1); > > > > ode45(@(t,Y) odefun(t,Y,vars),tspan,yf); > > > > > > > > The solution seemed reasonable. > > > > Just wondering if I "flipped" the result of the > initial > > > > value problem, does that make it a valid final value > > > > problem? Wondering how ode45 solves backwards in time > > > (when > > > > tspan has decreasing values). > > > > > > > > Any help at all would be appreciated.. > > > > Adam > > > > > > It may be because of your odefun. Could you post your > > > odefun here? > > > > > > Yi Cao > > > > Dear Adma > > Now I know what is your problem. You want to integrate the > differential Riccati equation in reverse time. The Riccati > equation in reverse time is unstable. Hence, a small > numerical error will eventually becomes infinite large. > That is why you feel you result is strange. If you look the > results in a short period, you will see this instability. > > Because your equation is not time varying, therefore, as > you mentioned before, it is better to integrate in forward > time, i.e. from [-30 0], then explain the results > reversely. > > hth. > Yi Cao
|
Pages: 1 Prev: SBML support in SimBiology Next: Read a *. File |