MaplePrimes Posts

MaplePrimes Posts are for sharing your experiences, techniques and opinions about Maple, MapleSim and related products, as well as general interests in math and computing.

Latest Post
  • Latest Posts Feed
  • Solving DAEs in Maple

    As I had mentioned in many posts, Maple cannot solve nonlinear DAEs. As of today (Maple 2015), given a system of index 1 DAE dy/dt = f(y,z); 0 = g(y,z), Maple “extends” g(y,z) to get dz/dt = g1(y,z). So, any given index 1 DAE is converted to a system of ODEs dy/dt = f, dz/dt = g1 with the constraint g = 0, before it solves. This is true for all the solvers in Maple despite the wrong claims in the help files. It is also true for MEBDFI, the FORTRAN implementation of which actually solves index 2 DAEs directly. In addition, the initial condition for the algebraic variable has to be consistent. The problem with using fsolve is that one cannot specify tolerance. Often times one has to solve DAEs at lower tolerances (1e-3 or 1e-4), not 1e-15. In addition, one cannot use compile =true for high efficiency.

    The approach in Maple fails for many DAEs of practical interest. In addition, this can give wrong answers. For example, dy/dt = z, y^2+z^2-1=0, with y(0)=0 and z(0)=1 has a meaningful solution only from 0 to Pi/2, Maple’s dsolve/numeric will convert this to dy/dt = z and dz/dt = -y and integrate in time for ever. This is wrong as at t = Pi/2, the system becomes index 2 DAE and there is more than 1 acceptable solution.

    We just recently got our paper accepted that helps Maple's dsolve and many ODE solvers in other languages handle DAEs directly. The approach is rather simple, the index 1 DAE is perturbed as dy/dt = f.S ; -mu.diff(g,t) = g. The switch function is a tanh function which is zero till t = tinit (initialization time). Mu is chosen to be a small number. In addition, lhs of the perturbed equation is simplified using approximate initial guesses as Maple cannot handle non-constant Mass matrix. The paper linked below gives below more details.

    http://depts.washington.edu/maple/pubs/U_Apprach_FULL_DRAFT.pdf  

    Next, I discuss different examples (code attached).

    Example 1: Simple DAE (one ODE and one AE), the proposed approach helps solve this system efficiently without knowing the exact initial condition.

    Hint: The code is given with a semicolon at the end of the most of the statements for educational purposes for new users. Using semicolon after dsolve numeric in classic worksheet crashes the code (Maplesoft folks couldn’t fix this despite my request).

    Example 2:

    This is a nickel battery model (one ODE and one AE). This fails with many solvers unless exact IC is given. The proposed approach works well. In particular, stiff=true, implicit=true option is found to be very efficient. The code given in example 1 can be used to solve example 2 or any other DAEs by just entering ODEs, AEs, ICs in proper places.

    Example 3:

    This is a nonlinear implicit ODE (posted in Mapleprimes earlier by joha, (http://www.mapleprimes.com/questions/203096-Solving-Nonlinear-ODE#answer211682 ). This can be converted to index 1 DAE and solved using the proposed approach.

    Example 4:

    This example was posted earlier by me in Mapleprimes (http://www.mapleprimes.com/posts/149877-ODEs-PDEs-And-Special-Functions) . Don’t try to solve this in Maple using its dsolve numeric solver for N greater than 5 directly. The proposed approach can handle this well. Tuning the perturbation parameters and using compile =true will help in solving this system more efficiently.

    Finally example 1 is solved for different perturbation parameters to show how one can arrive at convergence. Perhaps more sophisticated users and Maplesoft folks can enable this as automatically tuned parameters in dsolve/numeric.

    Note:

    This post should not be viewed as just being critical on Maple. I have wasted a lot of time assuming that Maple does what it claims in its help file. This post is to bring awareness about the difficulty in dealing with DAEs. It is perfectly fine to not have a DAE solver, but when literature or standard methods are cited/claimed, they should be implemented in proper form. I will forever remain a loyal Maple user as it has enabled me to learn different topics efficiently. Note that Maplesim can solve DAEs, but it is a pain to create a Maplesim model/project just for solving a DAE. Also, events is a pain with Maplesim. The reference to Mapleprimes links are missing in the article, but will be added before the final printing stage. The ability of Maple to find analytical Jacobian helps in developing many robust ODE and DAE solvers and I hope to post my own approaches that will solve more complicated systems.

    I strongly encourage testing of the proposed approach and implementation for various educational/research purposes by various users. The proposed approach enables solving lithium-ion and other battery/electrochemical storage models accurately in a robust manner. A disclosure has been filed with the University of Washington to apply for a provisional patent for battery models and Battery Management System for transportation, storage and other applications because of the current commercial interest in this topic (for batteries). In particular, use of this single step avoids intialization issues/(no need to initialize separately) for parameter estimation, state estimation or optimal control of battery models.

     

    Appendix A

    Maple code for Examples 1-4 from "Extending Explicit and Linealry Implicit ODE Solvers for Index-1 DAEs", M. T. Lawder,

    V. Ramadesigan, B. Suthar and V. R. Subramanian, Computers and Chemical Engineering, in press (2015).

    Use y1, y2, etc. for all differential variables and z1, z2, etc. for all algebraic variables

     

    Example 1

    restart;

    with(plots):

    Enter all ODEs in eqode

    eqode:=[diff(y1(t),t)=-y1(t)^2+z1(t)];

    eqode := [diff(y1(t), t) = -y1(t)^2+z1(t)]

    (1)

    Enter all AEs in eqae

    eqae:=[cos(y1(t))-z1(t)^0.5=0];

    eqae := [cos(y1(t))-z1(t)^.5 = 0]

    (2)

    Enter all initial conditions for differential variables in icodes

    icodes:=[y1(0)=0.25];

    icodes := [y1(0) = .25]

    (3)

    Enter all intial conditions for algebraic variables in icaes

    icaes:=[z1(0)=0.8];

    icaes := [z1(0) = .8]

    (4)

    Enter parameters for perturbation value (mu), switch function (q and tint), and runtime (tf)

    pars:=[mu=0.1,q=1000,tint=1,tf=5];

    pars := [mu = .1, q = 1000, tint = 1, tf = 5]

    (5)

    Choose solving method (1 for explicit, 2 for implicit)

    Xexplicit:=2;

    Xexplicit := 2

    (6)

    Standard solver requires IC z(0)=0.938791 or else it will fail

    solx:=dsolve({eqode[1],eqae[1],icodes[1],icaes[1]},numeric):

    Error, (in dsolve/numeric/DAE/checkconstraints) the initial conditions do not satisfy the algebraic constraints
      error = .745e-1, tolerance = .559e-6, constraint = cos(y1(t))-z1(t)^.5000000000000000000000

     

    ff:=subs(pars,1/2+1/2*tanh(q*(t-tint)));

    ff := 1/2+(1/2)*tanh(1000*t-1000)

    (7)

    NODE:=nops(eqode);NAE:=nops(eqae);

    NODE := 1

    NAE := 1

    (8)

    for XX from 1 to NODE do
    EQODE||XX:=lhs(eqode[XX])=rhs(eqode[XX])*ff;
    end do;

    EQODE1 := diff(y1(t), t) = (-y1(t)^2+z1(t))*(1/2+(1/2)*tanh(1000*t-1000))

    (9)

    for XX from 1 to NAE do
    EQAE||XX:=subs(pars,-mu*(diff(rhs(eqae[XX])-lhs(eqae[XX]),t))=rhs(eqae[XX])-lhs(eqae[XX]));
    end do;

    EQAE1 := -.1*sin(y1(t))*(diff(y1(t), t))-0.5e-1*(diff(z1(t), t))/z1(t)^.5 = -cos(y1(t))+z1(t)^.5

    (10)

     

    Dvars1:={seq(diff(z||x(t),t)=D||x,x=1..NAE)};

    Dvars1 := {diff(z1(t), t) = D1}

    (11)

    Dvars2:={seq(rhs(Dvars1[x])=lhs(Dvars1[x]),x=1..NAE)};

    Dvars2 := {D1 = diff(z1(t), t)}

    (12)

    icsn:=seq(subs(y||x(0)=y||x(t),icodes[x]),x=1..NODE),seq(subs(z||x(0)=z||x(t),icaes[x]),x=1..NAE);

    icsn := y1(t) = .25, z1(t) = .8

    (13)

    for j from 1 to NAE do

    EQAEX||j:=subs(Dvars1,eqode,icsn,Dvars2,lhs(EQAE||j))=rhs(EQAE||j);

    end do:

    Sys:={seq(EQODE||x,x=1..NODE),seq(EQAEX||x,x=1..NAE),seq(icodes[x],x=1..NODE),seq(icaes[x],x=1..NAE)};

    Sys := {-0.1824604200e-1-0.5590169945e-1*(diff(z1(t), t)) = -cos(y1(t))+z1(t)^.5, y1(0) = .25, z1(0) = .8, diff(y1(t), t) = (-y1(t)^2+z1(t))*(1/2+(1/2)*tanh(1000*t-1000))}

    (14)

    if Xexplicit=1 then

    sol:=dsolve(Sys,numeric):

    else

    sol:=dsolve(Sys,numeric,stiff=true,implicit=true):
    end if:

     

    for XX from 1 to NODE do
    a||XX:=odeplot(sol,[t,y||XX(t)],0..subs(pars,tf),color=red);
    end do:

    for XX from NODE+1 to NODE+NAE do
    a||XX:=odeplot(sol,[t,z||(XX-NODE)(t)],0..subs(pars,tf),color=blue);
    end do:

    display(seq(a||x,x=1..NODE+NAE),axes=boxed);

     

    End Example 1

     

    Example 2

    restart;

    with(plots):

    eq1:=diff(y1(t),t)=j1*W/F/rho/V;

    eq1 := diff(y1(t), t) = j1*W/(F*rho*V)

    (15)

    eq2:=j1+j2=iapp;

    eq2 := j1+j2 = iapp

    (16)

    j1:=io1*(2*(1-y1(t))*exp((0.5*F/R/T)*(z1(t)-phi1))-2*y1(t)*exp((-0.5*F/R/T)*(z1(t)-phi1)));

    j1 := io1*(2*(1-y1(t))*exp(.5*F*(z1(t)-phi1)/(R*T))-2*y1(t)*exp(-.5*F*(z1(t)-phi1)/(R*T)))

    (17)

    j2:=io2*(exp((F/R/T)*(z1(t)-phi2))-exp((-F/R/T)*(z1(t)-phi2)));

    j2 := io2*(exp(F*(z1(t)-phi2)/(R*T))-exp(-F*(z1(t)-phi2)/(R*T)))

    (18)

    params:={F=96487,R=8.314,T=298.15,phi1=0.420,phi2=0.303,W=92.7,V=1e-5,io1=1e-4,io2=1e-10,iapp=1e-5,rho=3.4};

    params := {F = 96487, R = 8.314, T = 298.15, V = 0.1e-4, W = 92.7, io1 = 0.1e-3, io2 = 0.1e-9, rho = 3.4, iapp = 0.1e-4, phi1 = .420, phi2 = .303}

    (19)

    eqode:=[subs(params,eq1)];

    eqode := [diff(y1(t), t) = 0.5651477584e-2*(1-y1(t))*exp(19.46229155*z1(t)-8.174162450)-0.5651477584e-2*y1(t)*exp(-19.46229155*z1(t)+8.174162450)]

    (20)

    eqae:=[subs(params,eq2)];

    eqae := [0.2e-3*(1-y1(t))*exp(19.46229155*z1(t)-8.174162450)-0.2e-3*y1(t)*exp(-19.46229155*z1(t)+8.174162450)+0.1e-9*exp(38.92458310*z1(t)-11.79414868)-0.1e-9*exp(-38.92458310*z1(t)+11.79414868) = 0.1e-4]

    (21)

    icodes:=[y1(0)=0.05];

    icodes := [y1(0) = 0.5e-1]

    (22)

    icaes:=[z1(0)=0.7];

    icaes := [z1(0) = .7]

    (23)

    solx:=dsolve({eqode[1],eqae[1],icodes[1],icaes[1]},type=numeric):

    Error, (in dsolve/numeric/DAE/checkconstraints) the initial conditions do not satisfy the algebraic constraints
      error = .447e9, tolerance = .880e4, constraint = -2000000*(-1+y1(t))*exp(19.46229155000000000000*z1(t)-8.174162450000000000000)-2000000*y1(t)*exp(-19.46229155000000000000*z1(t)+8.174162450000000000000)+exp(38.92458310000000000000*z1(t)-11.79414868000000000000)-exp(-38.92458310000000000000*z1(t)+11.79414868000000000000)-100000

     

    pars:=[mu=0.00001,q=1000,tint=1,tf=5001];

    pars := [mu = 0.1e-4, q = 1000, tint = 1, tf = 5001]

    (24)

    Xexplicit:=2;

    Xexplicit := 2

    (25)

    ff:=subs(pars,1/2+1/2*tanh(q*(t-tint)));

    ff := 1/2+(1/2)*tanh(1000*t-1000)

    (26)

    NODE:=nops(eqode):NAE:=nops(eqae);

    NAE := 1

    (27)

    for XX from 1 to NODE do
    EQODE||XX:=lhs(eqode[XX])=rhs(eqode[XX])*ff:
    end do;

    EQODE1 := diff(y1(t), t) = (0.5651477584e-2*(1-y1(t))*exp(19.46229155*z1(t)-8.174162450)-0.5651477584e-2*y1(t)*exp(-19.46229155*z1(t)+8.174162450))*(1/2+(1/2)*tanh(1000*t-1000))

    (28)

    for XX from 1 to NAE do
    EQAE||XX:=subs(pars,-mu*(diff(rhs(eqae[XX])-lhs(eqae[XX]),t))=rhs(eqae[XX])-lhs(eqae[XX]));
    end do;

    EQAE1 := -0.2e-8*(diff(y1(t), t))*exp(19.46229155*z1(t)-8.174162450)+0.3892458310e-7*(1-y1(t))*(diff(z1(t), t))*exp(19.46229155*z1(t)-8.174162450)-0.2e-8*(diff(y1(t), t))*exp(-19.46229155*z1(t)+8.174162450)+0.3892458310e-7*y1(t)*(diff(z1(t), t))*exp(-19.46229155*z1(t)+8.174162450)+0.3892458310e-13*(diff(z1(t), t))*exp(38.92458310*z1(t)-11.79414868)+0.3892458310e-13*(diff(z1(t), t))*exp(-38.92458310*z1(t)+11.79414868) = 0.1e-4-0.2e-3*(1-y1(t))*exp(19.46229155*z1(t)-8.174162450)+0.2e-3*y1(t)*exp(-19.46229155*z1(t)+8.174162450)-0.1e-9*exp(38.92458310*z1(t)-11.79414868)+0.1e-9*exp(-38.92458310*z1(t)+11.79414868)

    (29)

    Dvars1:={seq(diff(z||x(t),t)=D||x,x=1..NAE)};

    Dvars1 := {diff(z1(t), t) = D1}

    (30)

    Dvars2:={seq(rhs(Dvars1[x])=lhs(Dvars1[x]),x=1..NAE)};

    Dvars2 := {D1 = diff(z1(t), t)}

    (31)

    icsn:=seq(subs(y||x(0)=y||x(t),icodes[x]),x=1..NODE),seq(subs(z||x(0)=z||x(t),icaes[x]),x=1..NAE);

    icsn := y1(t) = 0.5e-1, z1(t) = .7

    (32)

    for j from 1 to NAE do

    EQAEX||j:=subs(Dvars1,eqode,icsn,Dvars2,lhs(EQAE||j))=rhs(EQAE||j);

    end do;

    EQAEX1 := -0.2e-8*(0.5368903705e-2*exp(5.449441630)-0.2825738792e-3*exp(-5.449441630))*exp(5.449441630)+0.3697835394e-7*(diff(z1(t), t))*exp(5.449441630)-0.2e-8*(0.5368903705e-2*exp(5.449441630)-0.2825738792e-3*exp(-5.449441630))*exp(-5.449441630)+0.1946229155e-8*(diff(z1(t), t))*exp(-5.449441630)+0.3892458310e-13*(diff(z1(t), t))*exp(15.45305949)+0.3892458310e-13*(diff(z1(t), t))*exp(-15.45305949) = 0.1e-4-0.2e-3*(1-y1(t))*exp(19.46229155*z1(t)-8.174162450)+0.2e-3*y1(t)*exp(-19.46229155*z1(t)+8.174162450)-0.1e-9*exp(38.92458310*z1(t)-11.79414868)+0.1e-9*exp(-38.92458310*z1(t)+11.79414868)

    (33)

    Sys:={seq(EQODE||x,x=1..NODE),seq(EQAEX||x,x=1..NAE),seq(icodes[x],x=1..NODE),seq(icaes[x],x=1..NAE)};

    Sys := {-0.5810962488e-6+0.8802389238e-5*(diff(z1(t), t)) = 0.1e-4-0.2e-3*(1-y1(t))*exp(19.46229155*z1(t)-8.174162450)+0.2e-3*y1(t)*exp(-19.46229155*z1(t)+8.174162450)-0.1e-9*exp(38.92458310*z1(t)-11.79414868)+0.1e-9*exp(-38.92458310*z1(t)+11.79414868), y1(0) = 0.5e-1, z1(0) = .7, diff(y1(t), t) = (0.5651477584e-2*(1-y1(t))*exp(19.46229155*z1(t)-8.174162450)-0.5651477584e-2*y1(t)*exp(-19.46229155*z1(t)+8.174162450))*(1/2+(1/2)*tanh(1000*t-1000))}

    (34)

    if Xexplicit=1 then

    sol:=dsolve(Sys,numeric,maxfun=0):

    else

    sol:=dsolve(Sys,numeric,stiff=true,implicit=true,maxfun=0):

    end if:

     

    for XX from 1 to NODE do
    a||XX:=odeplot(sol,[t,y||XX(t)],0..subs(pars,tf),color=red);
    end do:

    for XX from NODE+1 to NODE+NAE do
    a||XX:=odeplot(sol,[t,z||(XX-NODE)(t)],0..subs(pars,tf),color=blue);
    end do:

    b1:=odeplot(sol,[t,y1(t)],0..1,color=red):
    b2:=odeplot(sol,[t,z1(t)],0..1,color=blue):

    display(b1,b2,axes=boxed);

     

    display(seq(a||x,x=1..NODE+NAE),axes=boxed);

     

    End Example 2

     

    Example 3

    restart;

    with(plots):

    eq1:=diff(y1(t),t)^2+diff(y1(t),t)*(y1(t)+1)+y1(t)=cos(diff(y1(t),t));

    eq1 := (diff(y1(t), t))^2+(diff(y1(t), t))*(y1(t)+1)+y1(t) = cos(diff(y1(t), t))

    (35)

    solx:=dsolve({eq1,y1(0)=0},numeric):

    Error, (in dsolve/numeric/make_proc) Could not convert to an explicit first order system due to 'RootOf'

     

    eqode:=[diff(y1(t),t)=z1(t)];

    eqode := [diff(y1(t), t) = z1(t)]

    (36)

    eqae:=[subs(eqode,eq1)];

    eqae := [z1(t)^2+z1(t)*(y1(t)+1)+y1(t) = cos(z1(t))]

    (37)

    icodes:=[y1(0)=0.0];

    icodes := [y1(0) = 0.]

    (38)

    icaes:=[z1(0)=0.0];

    icaes := [z1(0) = 0.]

    (39)

    pars:=[mu=0.1,q=1000,tint=1,tf=4];

    pars := [mu = .1, q = 1000, tint = 1, tf = 4]

    (40)

    Xexplicit:=2;

    Xexplicit := 2

    (41)

    ff:=subs(pars,1/2+1/2*tanh(q*(t-tint)));

    ff := 1/2+(1/2)*tanh(1000*t-1000)

    (42)

    NODE:=nops(eqode);NAE:=nops(eqae);

    NODE := 1

    NAE := 1

    (43)

    for XX from 1 to NODE do
    EQODE||XX:=lhs(eqode[XX])=rhs(eqode[XX])*ff:
    end do;

    EQODE1 := diff(y1(t), t) = z1(t)*(1/2+(1/2)*tanh(1000*t-1000))

    (44)

    for XX from 1 to NAE do
    EQAE||XX:=subs(pars,-mu*(diff(rhs(eqae[XX])-lhs(eqae[XX]),t))=rhs(eqae[XX])-lhs(eqae[XX]));
    end do;

    EQAE1 := .1*sin(z1(t))*(diff(z1(t), t))+.2*z1(t)*(diff(z1(t), t))+.1*(diff(z1(t), t))*(y1(t)+1)+.1*z1(t)*(diff(y1(t), t))+.1*(diff(y1(t), t)) = cos(z1(t))-z1(t)^2-z1(t)*(y1(t)+1)-y1(t)

    (45)

     

    Dvars1:={seq(diff(z||x(t),t)=D||x,x=1..NAE)};

    Dvars1 := {diff(z1(t), t) = D1}

    (46)

    Dvars2:={seq(rhs(Dvars1[x])=lhs(Dvars1[x]),x=1..NAE)};

    Dvars2 := {D1 = diff(z1(t), t)}

    (47)

    icsn:=seq(subs(y||x(0)=y||x(t),icodes[x]),x=1..NODE),seq(subs(z||x(0)=z||x(t),icaes[x]),x=1..NAE);

    icsn := y1(t) = 0., z1(t) = 0.

    (48)

    for j from 1 to NAE do

    EQAEX||j:=subs(Dvars1,eqode,icsn,Dvars2,lhs(EQAE||j))=rhs(EQAE||j);

    end do;

    EQAEX1 := .1*sin(0.)*(diff(z1(t), t))+.1*(diff(z1(t), t)) = cos(z1(t))-z1(t)^2-z1(t)*(y1(t)+1)-y1(t)

    (49)

    Sys:={seq(EQODE||x,x=1..NODE),seq(EQAEX||x,x=1..NAE),seq(icodes[x],x=1..NODE),seq(icaes[x],x=1..NAE)};

    Sys := {.1*(diff(z1(t), t)) = cos(z1(t))-z1(t)^2-z1(t)*(y1(t)+1)-y1(t), y1(0) = 0., z1(0) = 0., diff(y1(t), t) = z1(t)*(1/2+(1/2)*tanh(1000*t-1000))}

    (50)

    if Xexplicit=1 then

    sol:=dsolve(Sys,numeric):

    else

    sol:=dsolve(Sys,numeric,stiff=true,implicit=true):

    end if:

     

    for XX from 1 to NODE do
    a||XX:=odeplot(sol,[t,y||XX(t)],0..subs(pars,tf),color=red);
    end do:

    for XX from NODE+1 to NODE+NAE do
    a||XX:=odeplot(sol,[t,z||(XX-NODE)(t)],0..subs(pars,tf),color=blue);
    end do:

    display(seq(a||x,x=1..NODE+NAE),axes=boxed);

     

    End Example 3

     

    Example 4

    restart;

    with(plots):

    N:=11:h:=1/(N+1):

    for i from 2 to N+1 do eq1[i]:=diff(y||i(t),t)=(y||(i+1)(t)-2*y||i(t)+y||(i-1)(t))/h^2-y||i(t)*(1+z||i(t));od:

    for i from 2 to N+1 do eq2[i]:=0=(z||(i+1)(t)-2*z||i(t)+z||(i-1)(t))/h^2-(1-y||i(t)^2)*(exp(-z||i(t)));od:

    eq1[1]:=(3*y1(t)-4*y2(t)+y3(t))/(2*h)=0: eq1[N+2]:=y||(N+2)(t)-1=0:

    eq2[1]:=(3*z1(t)-4*z2(t)+1*z3(t))/(2*h)=0: eq2[N+2]:=z||(N+2)(t)=0:

    eq1[1]:=subs(y1(t)=z||(N+3)(t),eq1[1]):

    eq1[N+2]:=subs(y||(N+2)(t)=z||(N+4)(t),eq1[N+2]):

    eqode:=[seq(subs(y1(t)=z||(N+3)(t),y||(N+2)(t)=z||(N+4)(t),eq1[i]),i=2..N+1)]:

    eqae:=[eq1[1],eq1[N+2],seq(eq2[i],i=1..N+2)]:

    icodes:=[seq(y||j(0)=1,j=2..N+1)]:

    icaes:=[seq(z||j(0)=0,j=1..N+2),z||(N+3)(0)=1,z||(N+4)(0)=1]:

    pars:=[mu=0.00001,q=1000,tint=1,tf=2]:

    Xexplicit:=2:

    ff:=subs(pars,1/2+1/2*tanh(q*(t-tint))):

    NODE:=nops(eqode):NAE:=nops(eqae):

    for XX from 1 to NODE do

    EQODE||XX:=lhs(eqode[XX])=rhs(eqode[XX])*ff: end do:

    for XX from 1 to NAE do

    EQAE||XX:=subs(pars,-mu*(diff(rhs(eqae[XX])-lhs(eqae[XX]),t))=rhs(eqae[XX])-lhs(eqae[XX])); end do:

    Dvars1:={seq(diff(z||x(t),t)=D||x,x=1..NAE)}:

    Dvars2:={seq(rhs(Dvars1[x])=lhs(Dvars1[x]),x=1..NAE)}:

    icsn:=seq(subs(y||x(0)=y||x(t),icodes[x]),x=1..NODE),seq(subs(z||x(0)=z||x(t),icaes[x]),x=1..NAE):

    for j from 1 to NAE do

    EQAEX||j:=subs(Dvars1,eqode,icsn,Dvars2,lhs(EQAE||j))=rhs(EQAE||j):

    end do:

    Sys:={seq(EQODE||x,x=1..NODE),seq(EQAEX||x,x=1..NAE),seq(icodes[x],x=1..NODE),seq(icaes[x],x=1..NAE)}:

    if Xexplicit=1 then

    sol:=dsolve(Sys,numeric,maxfun=0):

    else

    sol:=dsolve(Sys,numeric,stiff=true,implicit=true,maxfun=0):

    end if:

     

    for XX from 1 to NODE do

    a||XX:=odeplot(sol,[t,y||(XX+1)(t)],1..subs(pars,tf),color=red): end do:

    for XX from NODE+1 to NODE+NAE do

    a||XX:=odeplot(sol,[t,z||(XX-NODE)(t)],1..subs(pars,tf),color=blue): end do:

    display(seq(a||x,x=1..NODE),a||(NODE+NAE-1),a||(NODE+NAE),axes=boxed);

     

    End of Example 4

     

    Sometimes the parameters of the switch function and perturbation need to be tuned to obtain propoer convergence. Below is Example 1 shown for several cases using the 'parameters' option in Maple's dsolve to compare how tuning parameters affects the solution

    restart:

    with(plots):

    eqode:=[diff(y1(t),t)=-y1(t)^2+z1(t)]: eqae:=[cos(y1(t))-z1(t)^0.5=0]:

    icodes:=[y1(0)=0.25]: icaes:=[z1(0)=0.8]:

    pars:=[tf=5]:

    Xexplicit:=2;

    Xexplicit := 2

    (51)

    ff:=subs(pars,1/2+1/2*tanh(q*(t-tint))):

    NODE:=nops(eqode):NAE:=nops(eqae):

    for XX from 1 to NODE do
    EQODE||XX:=lhs(eqode[XX])=rhs(eqode[XX])*ff:
    end do:

    for XX from 1 to NAE do
    EQAE||XX:=subs(pars,-mu*(diff(rhs(eqae[XX])-lhs(eqae[XX]),t))=rhs(eqae[XX])-lhs(eqae[XX]));
    end do:

     

    Dvars1:={seq(diff(z||x(t),t)=D||x,x=1..NAE)}:

    Dvars2:={seq(rhs(Dvars1[x])=lhs(Dvars1[x]),x=1..NAE)}:

    icsn:=seq(subs(y||x(0)=y||x(t),icodes[x]),x=1..NODE),seq(subs(z||x(0)=z||x(t),icaes[x]),x=1..NAE):

    for j from 1 to NAE do

    EQAEX||j:=subs(Dvars1,eqode,icsn,Dvars2,lhs(EQAE||j))=rhs(EQAE||j):

    end do:

    Sys:={seq(EQODE||x,x=1..NODE),seq(EQAEX||x,x=1..NAE),seq(icodes[x],x=1..NODE),seq(icaes[x],x=1..NAE)}:

    if Xexplicit=1 then

    sol:=dsolve(Sys,numeric,'parameters'=[mu,q,tint],maxfun=0):

    else

    sol:=dsolve(Sys,numeric,'parameters'=[mu,q,tint],stiff=true,implicit=true):

    end if:

     

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

    plot1:=odeplot(sol,[t-1,y1(t)],0..4,color=red):
    plot2:=odeplot(sol,[t-1,z1(t)],0..4,color=blue):

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

    plot3:=odeplot(sol,[t-1,y1(t)],0..4,color=red,linestyle=dot):
    plot4:=odeplot(sol,[t-1,z1(t)],0..4,color=blue,linestyle=dot):

    display(plot1,plot2,plot3,plot4,axes=boxed);

     

    In general, one has to decrease mu, and increase q and tint until convergence (example at t=3)

    sol('parameters'=[0.001,10,1]):sol(3+1);

    [t = 4., y1(t) = .738587929442734, z1(t) = .546472878850096]

    (52)

    sol('parameters'=[0.0001,100,10]):sol(3+10);

    [t = 13., y1(t) = .738684397167344, z1(t) = .546618936273638]

    (53)

    sol('parameters'=[0.00001,1000,20]):sol(3+20);

    [t = 23., y1(t) = .738694113087217, z1(t) = .546633473784526]

    (54)

     

    The results have converged to 4 digits after the decimal. Of course, absolute and relative tolerances of the solvers can be modified if needed

     

    Download SolvingDAEsinMaple.mws

    I'd like to pay attention to Maple packages for symmetric functions, posets, root systems, and finite Coxeter groups by John Stembridge. That was estimated as well qualified in Mathoverflow.

    Dr Lopez,

    Thank you for your very interesting webinar on eigenpairs today. I especially valued your "aside" example of a matrix for which eigenvectors are "relatively simple," but which also has a "relatively simple" vector for which the magnitude is preserved, although not necessarily the direction. Your reply at the end of the program was very insightful, and I think it opens an interesting are of exploration.

    Juan Tolosa Richard Stockton College, NJ

    It looks like the Online Help has now been updated for Maple 2015.

    Here's the What's New in Maple 2015 Overview, which is similar to the product pages currently available here.

    But we can now also link to and view the online versions of full help pages of new or enhanced commands or example worksheets. For example, dataplot.

    acer

    @Markiyan Hirnyk   I try not to use this package, as I think the results are not reliable enough. Here is the example, where instead of the three real roots it finds only one, despite the hint to look for the three roots:

    restart;

    DirectSearch:-SolveEquations(100^x=x^100, AllSolutions, solutions=3);

     

    There are many other examples, particularly in discrete optimization in which it returns false results. Here is one example (well-known to you).

    I would like to pay attention to an article " Sums and Integrals: The Swiss analysis knife " by Bill Casselman, where the Euler-Maclaurin formula is discussed.  It should be noted all that matter is implemented in Maple through the commands bernoulli and eulermac. For example,

    bernoulli(666);


    eulermac(1/x, x);

    ,

    eulermac(sin(x), x, 6);

    BTW, as far as I know it, this boring stuff is substantially used in modern physics. The one is considered in

    Ronald Graham, Donald E. Knuth, and Oren Patashnik, Concrete mathematics, Addison-Wesley, 1989.

    The last chapter is concerned with the Euler-MacLaurin formula.


               

    Here are some tips and tricks that will help you get the most out of Maple 2015, covering from short cuts to how to use the newest features.

      1. Whenever you are asking yourself “..but how do I do it?”, just type ?Portal+Enter, and you will access the Maple Portal, which will give you a complete guide on how to do things.

      2. If you want to implement 1 of the 300 tasks that Maple offers in a syntax-free way, like Completing the Square, just follow this path: Tools≻Tasks≻Browse.

      3. Type Ctrl+F2 or Command+F2 and the Quick Reference window with shortcut keys and other information about working with the Maple interface will pop up.

      4. If you need quick help with a specific mathematical function, click or highlight the function + F2 and a Help box that contains a summary of the basic characteristics of the function will pop up.

      5. If you have installed the Excel Add-in and you want to perform some Maple commands within Excel, make sure to enable the Maple add in by following this path: Excel’s Tool Menu>Add-Ins>Select Maple Excel Add-in Box> OK

      6. Export Maple’s data into Excel by right clicking and choosing ‘Export As’>Excel.

      7. Instead of having to copy-paste your Maple information into a Power Point Presentation, just turn the slideshow mode on by pressing F11. This way you will have an interactive presentation that holds all the live plots and embedded components that Maple offers.

      8. Whenever you want to create interactive mini-applications that can be used to explore the parameters of any arbitrary Maple expression, such as a plot, mathematical equation, or command use the Exploration Assistant. Do this by either right-clicking +Explore from the context-sensitive menus, or by calling the Explore command.

      9. Save time while computing mathematical expressions by calling the equation label instead of having to re-type the equation. Do this by pressing CTRL+L and then input the number that identifies the equation.

      10. Reference mathematical equations or expressions from other documents. First, determine which label is associated with the equation you want. In the main document, select "Insert" > "Reference". From the file dialog, select the file containing the expression. Then select the equation reference number of your equation from the list that appears.

      11. In Maple, the letter "e" entered using the keyboard does not represent the exponential function. The exponential function can be entered using command completion (Ctrl+Space or ESC) or the "exp(a)" item in the Expression Palette (Standard interface only). The exponential can also be entered as:          
        > exp(x)

      12. With Maple 2015 you can now access data sets from various built-in and online data sources. This package is able to access time series data from the data aggregator Quandl, as well as locally installed data from countries and cities. To learn more, click here.

      13. Whenever you assign plots to a variable name, p:=[plot(sin(x)), plot(cos(x))] a thumbnail of the plot will appear instead of the code.

      14. Save time when inputting existing or personalized units. Just click CTRL+SHIFT+U and type the desired units you want.

      15. With Maple 2015 you can now zoom in or out just by pressing CTRL+SCROLL or CTRL+ place two fingers on the pad and move them up to zoom in or down to zoom out.

      16. Convert a Maple Worksheet into Microsoft Word: This can be done using the Export to HTML feature.
        1. Prepare your worksheet as you would like it to appear in the document.
        2. From the "File" menu in Maple, select "Export As ..." > "HTML".
        3. Give the HTML file a name, "output.html" for example.
        4. When the export has completed, start Word, and open the HTML file. If you used "output.html" as the name to save the file as, open the file called "output1.html" into Word.
        5. From the "File" menu in Word, select "Save as Word Document" to save the file. You now have a Word document which contains the content of your Maple worksheet.

          Note: this procedure will work with any Word Processing program that can open an HTML document.

      17. Change Maple’s default input from 2D to 1D:
        1. Open the Tools > Options... menu (Maple > Preferences on a MACINTOSH machine).
        2. Select the Display tab
        3. From "Input Display" menu select Maple Notation
        4. Press the Apply to Session button to make the change take effect for the current Maple session.
        5. Press Apply Globally to have the change take effect permanently. Maple will need to be restarted if you choose Apply Globally for the changes to take effect.

          You may download a set of instruction on how to change your 2D interface to the “Classic” Style here: ftp://public.maplesoft.com/miscellaneous/ChangeToClassicInterface.pdf

    We hope that you find this list helpful. Please feel free to add any of your tips or techniques to this post, or to create your own new topic.

    Last month, we received a very kind note from a recipient of one of our sponsorships. Maplesoft sponsors several academic and commercial events throughout the year, providing free copies of Maple or MapleSim to lucky attendees. Audrey was one of the winners of the Elgin Community College Calculus Contest, where she won a copy of Maple. Here’s what she had to say:

    Thank you so much for the Maple license.  I have become familiar with Maple during the last school year.  At first the commands were like Chinese to me and I had a rough time getting anything done, but once I made a connection between the commands and what they were doing it was a lot easier.  Even without former knowledge of computer programing, the commands are increasingly intuitive.  Maple has been a huge help to me doing my homework and projects, and even as I was studying for the competition it was useful for checking my answers.  Another reason that I love Maple is that it provides visuals for the difficult concepts we learned in class, such as shell method in Calc II and mixed partial derivatives in Calc III.  I enjoy math, but I thank that Maple has enriched my experience along the way.

    Thank you again for your generous gift, 

    ~Audrey~

    It’s always nice to hear how students and professionals alike are succeeding with the help of Maple. If you’d like to share your experience, please send an email to customerservice@maplesoft.com or post it here on MaplePrimes.

    You are teaching linear algebra, or perhaps a differential equations course that contains a unit on first-order linear systems. You need to get across the notion of the eigenpair of a matrix, that is, eigenvalues and eigenvectors, what they mean, how are they found, for what are they useful.

    Of course, Maple's Context Menu can, with a click or two of the mouse, return both eigenvalues and eigenvectors. But that does not satisfy the needs of the student: an answer has been given but nothing has been learned. So, of what use is Maple in this pedagogical task? How can Maple enhance the lessons devoted to finding and using eigenpairs of a matrix?

    In this webinar I am going to demonstrate how Maple can be used to get across the concept of the eigenpair, to show its meaning, to relate this concept to the by-hand algorithms taught in textbooks.

    Ah, but it's not enough just to do the calculations - they also have to be easy to implement so that the implementation does not cloud the pedagogic goal. So, an essential element of this webinar will be its Clickable format, free of the encumbrance of commands and their related syntax. I'll use a syntax-free paradigm to keep the technology as simple as possible while achieving the didactic goal.

    Notes added on July 7, 2015:

    We find recent applications of the components applied to the linear momentum, circular equations applied to engineering. Just simply replace the vector or scalar fields to thereby reasoning and use the right button.

     

    Momento_Lineal_y_Circular.mw

    (in spanish)

    Atte.

    L.AraujoC.

    A small piece of code for fun before the weekend, inspired by some recent posts:

    http://www.johndcook.com/blog/2015/06/03/mystery-curve/

    http://mathlesstraveled.com/2015/06/04/random-cyclic-curves-5/

    http://www.walkingrandomly.com/?p=5677

     

    cycler := proc(t, k, p, m, n, T) local expr, u, v;
      u := exp(k*I*t);
      expr := exp(I*t) * (1 - u/m + I*(u^(-p))/n);
      v := 1 + abs(1/n) + abs(1/m);
      plots:-complexplot( expr, t = 0 .. T, axes = none,
                          view = [-v .. v, -v .. v] );
    end proc:
    
    cycler(t, 5, 3, 2, 3, 2*Pi);
    

    And that can be made into a small application (needs Maple 18 or 2015),

    Explore( cycler(t, k, p, m, n, T),
             parameters = [ k = -10 .. 10, p = -10 .. 10,
                            m = -10.0 .. 10.0, n = -10.0 .. 10.0,
                            [ T = 0 .. 2*Pi, animate ] ],
             initialvalues = [ k = 5, p = 3, m = 2, n = 3, T = 2*Pi ],
             placement = left, animate = false, numframes = 100 );
    

    cyclerapp.mw

    The animation of parameter T from 0 to 2*Pi can also be fun if the view option is removed/disabled in the call to complexplot. (That could even be made a choice, by adding an additional argument for calling procedure cycler and an accompanying checkbox parameter on the exploration.)

    acer

    Maplesoft will be hosting the 2015 Maple T.A. User Summit this June 15 - 17 in New York City. Don’t miss this opportunity to learn about new trends in online education while networking and socializing with fellow educators and Maple T.A. users in the city that never sleeps!

    We are happy to announce that the schedule has been finalized! The event will include keynote presentations, talks and discussions from users and Maplesoft staff, training sessions, a welcome reception and a boat cruise around New York City, 

    If you'd like ot sign-up but still haven't - don't hesitate to do so today using the following link: https://webstore.maplesoft.com/taconference/register.aspx .

    I hope to see you there!

    Jonny
    Maplesoft Product Manager, Maple T.A.

    Developed and then implemented with open code components. It is very important to note this post is held for students of civil engineering and mechanics. Using advanced mathematical concepts to concepts in engineering.

    Metodos_Energeticos_full.mw

    (in spanish)

    Atte.

    L.Araujo.C

     

     

     

     

     

    On a related post here, I have posted some screen shots for fun. Today is a special day for me in particular, because I passed my PhD viva with minor corrections! If you look colsely on the date, by coincidence, it was TWO years ago exactly. So I feel like I maybe 'update' the old post with a bit more, to make it V2.

     

    So here comes the new screent shots: (Bear with me for now, I will post some actual content about how I feel when using Maple later.)

    Alright, enough with the screent shots. If you click to see the big picture, you would notice that I have managed to get a complete sets of Maple versions from Maple V to Maple 2015!

     

    ===============================================

    I am originally from Shanghai and I have always done well in Maths and science. I first heard about Maple in 2004 from a Maths teacher. He introduced me to this software. I played just a couple of times with Maple 6 on his computer, to get a first impression. At that time, all I could say was, hmmm insteresting.

     

    In 2006, I went to UK for a foundation course. That was the first time I was actually taught how to use Maple 9.5. So I had access to it on the university computers. I discovered a lot about Maple and used it for ALL my Maths homeworks. Yes, I am lazy. I hope that Maple can do everything!

     

    Then I got fascinated with Maple. Unfortunately, Maple was not taught in the undergraduate course. But there are materials for self-learning. By that time, I had become quite good with most of the contents in those materials. So I went look for other things to try. I went to ask my foundation course classmates, to see if they have anything on Maple and if they needed the help. One of them was at Imperial College and the questions were a bit chanlleging (finally!). That was the time I first met MaplePrimes! Hello, how have you been?

     

    After that I have never stopped using Maple or Maple Primes. I may have been quite on the forum, but I was there. My PhD research rely hugely on the ability to compute the symbolic rank of certain matrices as well as the ability to simplifiying complicated expressions using siderules.

     

    I do not want to talk too much about the technical details when using Maple. But I do

    THANK Maple and it creators, developers and all relavent staff around the globe.

    THANK Maple Primes and all its users. Some users have been particulary helpful!

     

    Lastly, I dont have any other words to say other than this:

    It's been really fun and enjoyable. Thanks!

     

     

    This post is related to the this thread

    The recursive procedure  PosIntSolve  finds the number of non-negative or positive solutions of any linear Diophantine equation

    a1*x1+a2*x2+ ... +aN*xN = n  with positive coefficients a1, a2, ... aN .  

    Formal parameters: L is the list of coefficients of the left part, n  is the right part,  s (optional) is nonneg (by default) for nonnegint solutions and  pos  for positive solutions.

    The basic ideas:

    1) If you make shifts of the all unknowns by the formulas  x1'=x1-1,  x2'=x2-1, ... , xN'=xN-1  then  the number of positive solutions of the first equation equals the number of non-negative solutions of the second equation.

    2) The recurrence formula (penultimate line of the procedure) can easily be proved by induction.

     

    The code of the procedure:

    restart;

    PosIntSolve:=proc(L::list(posint), n::nonnegint, s::symbol:=nonneg)

    local N, n0;

    option remember;

    if s=pos then n0:=n-`+`(op(L)) else n0:=n fi;

    N:=nops(L);

    if N=1 then if irem(n0,L[1])=0 then return 1 else return 0 fi; fi;

    add(PosIntSolve(subsop(1=NULL,L),n0-k*L[1]), k=0..floor(n0/L[1]));

    end proc:

     

    Examples of use.

     

    Finding of the all positive solutions of equation 30*a+75*b+110*c+85*d+255*e+160*f+15*g+12*h+120*i=8000:

    st:=time():

    PosIntSolve([30,75,110,85,255,160,15,12,120], 8000, pos);

    time()-st;

                                           13971409380

                                                 2.125

     

    To test the procedure, solve (separately for non-negative and positive solutions) the simple equation  2*x1+7*x2+3*x3=2000  in two ways (by the  procedure and brute force method):

    ts:=time():

    PosIntSolve([2,7,3], 2000);

    PosIntSolve([2,7,3], 2000, pos);

    time()-ts;

                    47905

                    47334

                     0.281

     

    ts:=time():

    k:=0:

    for x from 0 to 2000/2 do

    for y from 0 to floor((2000-2*x)/7) do

    for z from 0 to floor((2000-2*x-7*y)/3) do

    if 2*x+7*y+3*z=2000 then k:=k+1 fi;

    od: od: od:

    k; 

    k:=0:

    for x from 1 to 2000/2 do

    for y from 1 to floor((2000-2*x)/7) do

    for z from 1 to floor((2000-2*x-7*y)/3) do

    if 2*x+7*y+3*z=2000 then k:=k+1 fi;

    od: od: od:

    k;

    time()-ts; 

                       47905

                       47334

                       50.063

     

    Another example - the solution of the famous problem: how many ways can be exchanged $ 1 using the coins of smaller denomination.

    PosIntSolve([1,5,10,25,50],100);

                            292

     

     Number-of-solutions.mw

     

     Edit.  The code has been slightly edited 

    First 67 68 69 70 71 72 73 Last Page 69 of 297