Venkat Subramanian

386 Reputation

13 Badges

15 years, 243 days

MaplePrimes Activity


These are replies submitted by

@Carl Love 

 

Thanks. Agreed. Perhaps time lapse in posts and I am always confused using the mapleprimes not sure of which post is current or latest.

@Preben Alsholm 

 

Even in the DAE format one can specify u(0)=alpha, and then add alpha to the parameters list. But alpha should come from the fsolve.

@Preben Alsholm 

If there are multiple solutions for the nonlinear equation, then there will be a different solution for each case. The user will have to decide what makes sense.

If all the roots are meaningul, then there is more than solution for the nonlinear ODE just like we have multiple roots for quadratic or nonlinear equations. 

 

There is no ODE solver in the world which can solve and give results for all possible solutions numerically (as of now in my experience and search). If the model is known to have multiple solutions, there are approaches to get those solutions and software available for the same (only the final steady state values).

@Carl Love 

 

The values of the parameters should be the set by the user. Non zero values also work. See code attached. But fsolve needs to be used to find the initial condition.

 

restart:

ODE1:=A*u(t)^2+B*u(t)*(h(t)+C)+E*h(t)=F*cos(u(t));

ODE1 := A*u(t)^2+B*u(t)*(h(t)+C)+E*h(t) = F*cos(u(t))

(1)

eqic:=A*u1^2+B*u1*C=F*cos(u1);

eqic := A*u1^2+B*C*u1 = F*cos(u1)

(2)

subs(A=1,B=1,C=1,F=1,eqic);

u1^2+u1 = cos(u1)

(3)

fsolve(%);

.5500093499

(4)

 For the simulation shown u has an initial condition of Pi/2. When parameters change, change ic accordingly.

ODE2:=diff(h(t),t)=u(t):

sol:=dsolve({ODE1,ODE2,h(0)=0,u(0)=.5500093499},type=numeric,parameters=[A,B,C,E,F],stiff=true,maxfun=0):

sol('parameters'=[1,1,1,1,1]):

with(plots):

odeplot(sol,[t,h(t)],0..10);

 

odeplot(sol,[t,u(t)],0..10);

 

 

 

Download convertimplicitODEtoDAE.mws

@acer 

 

It works for me in Maple 17 with the commands/code I posted. I was trying to warn the user to not expect this method to work for large scale implicit ODEs.

 

@Dave L 

I think it will be great to have an fsolve option for a very simple Newton Raphson method, wherein we are guaranteed an ouput with Digits =15  and specified absolute and relative tolerances and a maximum number of iterations. Displaying the iterations is also a great addtion to have so that users will know if there is a progress being made.

 

 

 

@aylin 

 

Aylin, as shown in the paper, control variables are given by min max commands which are found by solving for the costate equations for bounds if you were to write them.

 

Once you write down u values, then it is just simulation and is easy to solve. The paper is trying to solve a multi objective problem (by adding weights to different objectives). The problem is badly scaled (in the original Maple code). As of now the major contribution to the objective is from x[1] and not u[1], u[2]. If x[1] is not changing much, just optimizing the other two terms might give faster convergence.

Thanks for this problem, when I find time, I will post a solution for this.

@aylin 

You are welcome. Based on the discussion so far, it is fair to say that you are new to this field.  There are two main approaches to solve these problems, indirect methods and direct methods (Pontyragin). For unconstrained, unbounded problems it is easy to do direct methods. For bounded problems, you have to add costates for each bounds for every state and control variable.

Direct methods can be of 3 types, control vector parameterization, multipleshooting and simultanesous optimizations. If you care only for the solution, then I can write something up and email for the direct methods.

 

 

@ 

once we have a meaningful profile for x[1], x[2], x[3] with some optimum constant values for u[1], u[2], one can provide this as an initial guess for the bvp by using approxsoln = sol0 (where sol0 is a good initial guess from the IVP solver).

@aylin 

 

Is there a physical meaning for x[1], x[2], x[3]? Are they expected to be positive? I wrote a simple code in which I solved only for the original ODEs with u[1] and u[2] as parameters (not changing with time). Increasing u[1] and u[2] seems to increase your objective but x[2] becomes negative.

 

If x[1], x[2], x[3] are expected to be positive then you need to add adjoint or costate variables for that. You might want to scale the variables and objective so that they are nearly 1. Right now it varies by a wide range.

 

restart:
unprotect('gamma');

L:=x[1]-A[1]*(u[1])^2/2-A[2]*(u[2])^2/2;

L := x[1]-(1/2)*(A[1]*u[1]^2)-(1/2)*(A[2]*u[2]^2)

(1)

H:=L+psi[1](t)*(lambda-mu*x[1]-(1-u[1])*beta*x[1]*x[3]+delta*x[2])+psi[2](t)*((1-u[1])*beta*x[1]*x[3]-sigma*x[2])
+psi[3](t)*((1-u[2])*k*x[2]-gamma*x[3]);

H := x[1]-(1/2)*(A[1]*u[1]^2)-(1/2)*(A[2]*u[2]^2)+psi[1](t)*(lambda-mu*x[1]-(1-u[1])*beta*x[1]*x[3]+delta*x[2])+psi[2](t)*((1-u[1])*beta*x[1]*x[3]-sigma*x[2])+psi[3](t)*((1-u[2])*k*x[2]-gamma*x[3])

(2)

du1:=diff(H,u[1]);

du1 := -A[1]*u[1]+psi[1](t)*beta*x[1]*x[3]-psi[2](t)*beta*x[1]*x[3]

(3)

du2:=diff(H,u[2]);

du2 := -A[2]*u[2]-psi[3](t)*k*x[2]

(4)

ddu1:=-A[1]*u[1]+psi[1](t)*beta*x[1]*x[3]-psi[2](t)*beta*x[1]*x[3];

ddu1 := -A[1]*u[1]+psi[1](t)*beta*x[1]*x[3]-psi[2](t)*beta*x[1]*x[3]

(5)

ddu2:=-A[2]*u[2]-psi[3](t)*k*x[2];

ddu2 := -A[2]*u[2]-psi[3](t)*k*x[2]

(6)

sol_u1 := solve(ddu1, u[1]);

sol_u1 := beta*x[1]*x[3]*(psi[1](t)-psi[2](t))/A[1]

(7)

sol_u2 := solve(ddu2, u[2]);

sol_u2 := -psi[3](t)*k*x[2]/A[2]

(8)

Dx2:=subs(u[1]=beta*x[1]*x[3]*(psi[1](t)-psi[2](t))/A[1],u[2]=-psi[3](t)*k*x[2]/A[2], H );

Dx2 := x[1]-(1/2)*(beta^2*x[1]^2*x[3]^2*(psi[1](t)-psi[2](t))^2/A[1])-(1/2)*(psi[3](t)^2*k^2*x[2]^2/A[2])+psi[1](t)*(lambda-mu*x[1]-(1-beta*x[1]*x[3]*(psi[1](t)-psi[2](t))/A[1])*beta*x[1]*x[3]+delta*x[2])+psi[2](t)*((1-beta*x[1]*x[3]*(psi[1](t)-psi[2](t))/A[1])*beta*x[1]*x[3]-sigma*x[2])+psi[3](t)*((1+psi[3](t)*k*x[2]/A[2])*k*x[2]-gamma*x[3])

(9)

ode1:=diff(psi[1](t),t)=-diff(H,x[1]);

ode1 := diff(psi[1](t), t) = -1-psi[1](t)*(-mu-(1-u[1])*beta*x[3])-psi[2](t)*(1-u[1])*beta*x[3]

(10)

ode2:=diff(psi[2](t),t)=-diff(H,x[2]);

ode2 := diff(psi[2](t), t) = -psi[1](t)*delta+psi[2](t)*sigma-psi[3](t)*(1-u[2])*k

(11)

ode3:=diff(psi[3](t),t)=-diff(H,x[3]);

ode3 := diff(psi[3](t), t) = psi[1](t)*(1-u[1])*beta*x[1]-psi[2](t)*(1-u[1])*beta*x[1]+psi[3](t)*gamma

(12)

restart:
#Digits:=10:
unprotect('gamma');
lambda:=5*10^5:
mu:=0.003:
beta:=4*10^(-10):
delta:=0:
alpha:=0.043:
sigma:=alpha+delta:
k:=6.24:
gamma:=0.65:
A[1]:=10:
A[2]:=2:
#u[1]:=beta*x[1](t)*x[3](t)*(psi[1](t)-psi[2](t))/A[1]:
#u[2]:=-psi[3](t)*k*x[2](t)/A[2]:

ics := x[1](0)=1.7*10^8, x[2](0)=0,x[3](0)=400,psi[1](20)=0,psi[2](20)=0,psi[3](20)=0:

ode1:=diff(x[1](t), t)=lambda-mu*x[1](t)-(1-u[1])*beta*x[1](t)*x[3](t)+delta*x[2](t),
diff(x[2](t), t) =(1-u[1])*beta*x[1](t)*x[3](t)-sigma*x[2](t),
diff(x[3](t), t) =(1-u[2])*k*x[2](t)-gamma*x[3](t),
diff(psi[1](t), t) =-1+mu*psi[1](t)+beta*x[3](t)*(1-u[1])*(psi[1](t)-psi[2](t)),
diff(psi[2](t), t) =delta*psi[1](t)+sigma*psi[2](t)-psi[3](t)*(1-u[2])*k,
diff(psi[3](t), t) = beta*x[1](t)*(psi[1](t)-psi[2](t))*(1-u[1])+gamma*psi[3](t);

ode1 := diff(x[1](t), t) = 500000-0.3e-2*x[1](t)-(1/2500000000)*((1-u[1])*x[1](t)*x[3](t)), diff(x[2](t), t) = (1/2500000000)*((1-u[1])*x[1](t)*x[3](t))-0.43e-1*x[2](t), diff(x[3](t), t) = 6.24*(1-u[2])*x[2](t)-.65*x[3](t), diff(psi[1](t), t) = -1+0.3e-2*psi[1](t)+(1/2500000000)*(x[3](t)*(1-u[1])*(psi[1](t)-psi[2](t))), diff(psi[2](t), t) = 0.43e-1*psi[2](t)-6.24*psi[3](t)*(1-u[2]), diff(psi[3](t), t) = (1/2500000000)*(x[1](t)*(psi[1](t)-psi[2](t))*(1-u[1]))+.65*psi[3](t)

(13)

sol:=dsolve([ode1,ics],numeric, method = bvp[midrich],maxmesh=500);

Error, (in dsolve/numeric/bvp/convertsys) too few boundary conditions: expected 8, got 6

 

 

eq1:=diff(x[1](t), t)=lambda-mu*x[1](t)-(1-u[1])*beta*x[1](t)*x[3](t)+delta*x[2](t);
eq2:=diff(x[2](t), t) =(1-u[1])*beta*x[1](t)*x[3](t)-sigma*x[2](t);
eq3:=diff(x[3](t), t) =(1-u[2])*k*x[2](t)-gamma*x[3](t);

eq1 := diff(x[1](t), t) = 500000-0.3e-2*x[1](t)-(1/2500000000)*((1-u[1])*x[1](t)*x[3](t))

eq2 := diff(x[2](t), t) = (1/2500000000)*((1-u[1])*x[1](t)*x[3](t))-0.43e-1*x[2](t)

eq3 := diff(x[3](t), t) = 6.24*(1-u[2])*x[2](t)-.65*x[3](t)

(14)

eq4:=diff(Q(t),t)=x[1](t)-A[1]*(u[1])^2/2-A[2]*(u[2])^2/2;

eq4 := diff(Q(t), t) = x[1](t)-5*u[1]^2-u[2]^2

(15)

ics:=x[1](0)=1.7*10^8, x[2](0)=0,x[3](0)=400,Q(0)=0;

ics := x[1](0) = 170000000.0, x[2](0) = 0, x[3](0) = 400, Q(0) = 0

(16)

sol0:=dsolve({eq1,eq2,eq3,eq4,ics},type=numeric,stiff=true,'parameters'=[u[1],u[2]],abserr=1e-15,relerr=1e-12,maxfun=0,range=0..20):

with(plots):

Q0:=0;

Q0 := 0

(17)

obj:=proc(u)

global sol0,Q0;
local ob1;
try
sol0('parameters'=[u[1],u[2]]):
ob1:=subs(sol0(20.),Q(t)):
catch :
ob1:=0;
end try;
#ob1:=subs(sol0(20.),Q(t));
if ob1>Q0 then Q0:=ob1;print(Q0,u);end;
ob1;
end proc;

obj := proc (u) local ob1; global sol0, Q0; try sol0('parameters' = [u[1], u[2]]); ob1 := subs(sol0(20.), Q(t)) catch: ob1 := 0 end try; if Q0 < ob1 then Q0 := ob1; print(Q0, u) end if; ob1 end proc

(18)

obj([1,1]);

3398039287.12889, [1, 1]

3398039287.12889

(19)

obj([3,2.5]);

10853691356.1391, [3, 2.5]

10853691356.1391

(20)

u0:=Vector(2,[0.,0.],datatype=float[8]);

u0 := Vector(2, {(1) = 0., (2) = 0.})

(21)

 

Q0:=0;

Q0 := 0

(22)

with(Optimization);

[ImportMPS, Interactive, LPSolve, LSSolve, Maximize, Minimize, NLPSolve, QPSolve]

(23)

sol2:=NLPSolve(2,obj,initialpoint=u0,method=nonlinearsimplex,maximize,evaluationlimit=100):

3.39794371555394*10^9, Vector[row](2, {(1) = 0., (2) = 0.})

3.39803930712891*10^9, Vector[row](2, {(1) = 1., (2) = 0.})

3.39804033045244*10^9, Vector[row](2, {(1) = 1.49794733500399, (2) = 1.50623284257974})

3.39805145390838*10^9, Vector[row](2, {(1) = 1.87243416875499, (2) = 1.69451194790220})

3.40712818224986*10^9, Vector[row](2, {(1) = 2.24692100250599, (2) = 2.63590747451454})

3.51729809603447*10^9, Vector[row](2, {(1) = 2.20011014828712, (2) = 3.27134945497786})

3.53967508580218*10^9, Vector[row](2, {(1) = 2.57459698203812, (2) = 2.70651213901046})

3.74232674396347*10^9, Vector[row](2, {(1) = 3.27675979532124, (2) = 2.21227948753899})

3.94430211657206*10^9, Vector[row](2, {(1) = 2.57313414284378, (2) = 2.86757902989179})

4.26156884348600*10^9, Vector[row](2, {(1) = 2.97422636444183, (2) = 2.47994287384092})

5.12441431374667*10^9, Vector[row](2, {(1) = 2.92537553525273, (2) = 2.54569519139944})

2.46892011415654*10^10, Vector[row](2, {(1) = 3.07878508154351, (2) = 2.44069316166875})

8.93112347088505*10^10, Vector[row](2, {(1) = 3.20642994395782, (2) = 2.35054875107964})

1.37406629736151*10^11, Vector[row](2, {(1) = 3.12422642131584, (2) = 2.40814677044507})

3.97704555922777*10^11, Vector[row](2, {(1) = 3.15722253153225, (2) = 2.38467382241256})

5.39937222970221*10^11, Vector[row](2, {(1) = 3.14072447642405, (2) = 2.39641029642882})

3.33023882593904*10^12, Vector[row](2, {(1) = 3.18182623774504, (2) = 2.36761128674610})

2.12196697026660*10^13, Vector[row](2, {(1) = 3.18125786060723, (2) = 2.36800986932868})

Warning, limiting number of function evaluations reached

(24)

sol0('parameters'=[3.18125786060723, 2.36800986932868]);

[`u[1]` = 3.18125786060723, `u[2]` = 2.36800986932868]

(25)

for i from 1 to 3 do odeplot(sol0,[t,x[i](t)],0..20,thickness=3,axes=boxed);od;

 

 

 

 

Download mapleprimeVS.mws

@aylin 

 

Aylin, thanks for the problem statement and the code. Can you clarify what your objective is (Cost function) and how you got the BCS.

 

If you are trying to minimize integral of L, then it might result in a singular control problem.

Carl,

Thanks. I asked the original poster to post the original control problem. My current thought is that problem formulation in BVP form is wrong. Typically control variables appear in the original ODEs, not adjoints.

 

From the Hamiltonian and minimum principles, sometimes one can write control variable as a function of adjoints and state variables (ODE variables).

Depending on the objectives, one of the adjoint variable is likely to be non zero for the boundary condition. Without knowing the original problem statement, we cannot determine this.

 

To add to this, it is perfectly fine with limitations coming from singularity, etc. It is always left to the user to try to fix these things. 

 

An important point I would like to bring up is that when CAS is written, please implement the algorithm as is and don't do things that do not reflect the research algorithms or corresponding papers accurately.

 

http://www.mapleprimes.com/posts/149877-ODEs-PDEs-And-Special-Functions

 

In the link above, I showed an example of how Maple fails to solve DAEs. The truth of the matter is that at this point in time, Maple does not have a direct DAE solver. It only has ODE solvers. It converts DAE to ODEs and then solves. This point should be made clear in the help page for DAEs. I had spent a lot of time hoping that Maple does what it claims it does. In my opinion, Maplesoft will get more credit if help files reflect and convey these limitations.

All the DAE solvers in Maple have the same issue. The MEBDFI code is based on an algorithm from Dr. Jeff Cash. Unforuntately the Maple code only does ODEs. For DAEs, it converts to ODEs and then solves. This is not the original mebdfi code Professor Cash has published in the literature (implemented in FORTRAN).

 

My request is that when Maplesoft changes things in algorithms or methods while following a paper or work, please indicate apriori to not waste researchers and students' time. 

PS,  I have modified the Maple code so that one can solve this problem and I can share it if there is interest. I am a longtime user of Maple (from Maple V) and will be a lifetime user of Maple classic worksheet.

Edit:

1. I want to add that Maplesoft folks (in particular Allan Wittkopf) and others are very knowledgeable and very helpful. My guess is they are not staffed enough to update help pages (but this is not an excuse to misrepresent facts). My suggestion would be to add a wiki page for help pages and let the users update them with the caveat that Maplesoft does not own responsbility for the same. This way, when a new user goes to a help page, if there was a linked wiki page then one can read that for typos, algorithms used or modfified.

 2. At this point in time, Maple converts DAEs to explicit ODEs (dy/dt = f). If it is not able to do so, then the code will crash often times sucking up more than 1GB of RAM.

 

 

Hi All,

I just installed Maple 18. Yet to check all the new features. Looks like Maple does not provide the option to interact with NAG anymore.

 

This is a significant backward step. I am not sure why.

 

Thanks

Venkat Subramanian

@Allan Wittkopf 

 

Allan,

Thanks for your attention. Just like fsolve/sysnewton, if there are some specific commands that can be used to directly specify equations with variables and initial conditions in proper order (mapped) directly, then that would be great.

Also, please consider providing for direct solution of Mdy/dt =f as discussed here where M is singular for index-1DAE and do direct implicit solver for integration. That will help solve many difficult largescale index-1DAEs.

Note that we should continue to have the current facility to map and identify equations, variables and DAE index,etc. Just that for largescale ( any reasonably sized/difficult) PDEs and DAEs, we need a different/direct approach.

 

Venkat Subramanian

www.maple.eece.wustl.edu

First 14 15 16 17 Page 16 of 17