tomleslie

13876 Reputation

20 Badges

15 years, 174 days

MaplePrimes Activity


These are answers submitted by tomleslie

the attached, although as VV has pointed you will have two watch for Maple's automatic simplification (and maybe other things I haven't considered!)

  restart;
  g:= proc(z)
           local f:=p->op([0..nops(p)],p):
           if   numelems(indets(z, name))=2
           then if   op(0,z)=`+`
                then if   member(-1, f~({f(z)}))
                     then return `-`;
                     else return `+`;
                     fi:
                elif op(0,z)=`*`
                then if   member(-1, f~({f(z)}))
                     then return `/`;
                     else return `*`;
                     fi:
                elif op(0,z)=`^`
                then return `^`;
                fi;
           else error "Does not have two operands":
           fi
      end proc:

  g(a+b);
  g(a-b);
  g(a*b);
  g(a/b);
  g(a^b);
  g(a*b+c);

`+`

 

`-`

 

`*`

 

`/`

 

`^`

 

Error, (in g) Does not have two operands

 

 

Download typrs.mw

and which is a 'constant'. Unless you specify Maple (probably) just uses indets() which returns the indetermiinates in lexicographic order - which is alphabetic, except that all upper case names precede  lower case ones.

Consider

indets(-v1+a);
indets(-V1+a);
                            {a, v1}
                            {V1, a}


so when you ask for

restart;
sign(-v1+a);
sign(-V1+a);

the first retuirns the sign of 'a', and the second returns the sign of V1. If you want too avoid this, specify the indeterminate, as in

sign(-v1+a, [v1]);
sign(-V1+a, [V1]);
                               -1
                               -1

which returns -1 in both cases

restart:
List1 := [v1,v2,v3,v4];
List2 := [a*b/c, a/c,a*b-2,d];
computation := subs( List1=~List2, v1*diff(expr1(x),x)+v3*diff(expr2(y),y)+ v3*v4);

 

In the attached your "pedal curve" is calculated two ways, with and without using a procedure.

Ouput "renders" better in a workeheet than it does on this site - honest

  restart;

  Trunc := proc(F::{`+`, procedure}, odr::posint := 2, v::(list(name)) := [x, y])
                 local f;
                 description " Truncates an algebraic equation to required degree";
                 f := `if`(F::procedure, F(v[]), F);
                 if not f::`+`
                 then error "Can't truncate 1-term expression";
                 else select(q->degree(q, v) <= odr, f);
                 end if;
           end proc:
  C := (x^2+y^2+12*x+9)^2-4*(2*x+3)^3:
  xp1 := 1:
  yp1 := 2:
  p21 := plots:-implicitplot(C,
                             x = -3 .. 3,
                             y = -5 .. 5,
                             colour = "Salmon",
                             gridrefine = 2,
                             size = [300, 300]
                            ):

  sol1 := [solve(C, y)]:
  f1 := expand
        ( eval
          ( C,
            [x = X+r, y = Y+s]
          )
        ):
  ltg1 := expand
          ( eval
            ( Trunc(f1, 1, [Y, X]),
              [X = x-r, Y = y-s]
            )
          ):
  lprp1 := -coeff(ltg1, y)*x+coeff(ltg1, x)*y+K1:
  for i to nops(sol1) do
      Pedal||i := rhs~( solve
                        ( eval
                          ( [ ltg1,
                              eval
                              ( lprp1,
                                [ K1 = solve
                                       ( eval
                                         ( lprp1,
                                           [x = xp1, y = yp1]
                                         ),
                                         K1
                                       )
                                ]
                              )
                            ],
                            s = eval(sol1[i], x = r)
                          ),
                          [x, y]
                        )[]
                      )[];
      p9||i := plot( [Pedal||i, r = -20 .. 20],
                     colour = "MediumSeaGreen"
                   );
  end do:
  plots:-display( p21, seq(p9 || i, i = 1 .. nops(sol1)),
                  size = [600, 600],
                  scaling = constrained,
                  caption = " Curve and it's Pedal curve"
                );

 

NULL

 

  restart;

  Trunc := proc(F::{`+`, procedure}, odr::posint := 2, v::(list(name)) := [x, y])
                 local f;
                 description " Truncates an algebraic equation to required degree";
                 f := `if`(F::procedure, F(v[]), F);
                 if not f::`+`
                 then error "Can't truncate 1-term expression";
                 else select(q->degree(q, v) <= odr, f);
                 end if;
           end proc:
  C := (x^2+y^2+12*x+9)^2-4*(2*x+3)^3:
  xp1 := 1:
  yp1 := 2:
  p21 := plots:-implicitplot(C,
                             x = -3 .. 3,
                             y = -5 .. 5,
                             colour = "Salmon",
                             gridrefine = 2,
                             size = [300, 300]
                            ):

  Pedal:=proc( Curv, xp, yp)
               local i, sol1, f1, ltg1,lprp1;
               sol1:= [ solve(Curv, y) ];
               f1:= expand
                    ( eval
                      ( Curv,
                        [x = X+r, y = Y+s]
                      )
                    );
               ltg1:= expand
                      ( eval
                        ( Trunc( f1, 1, [Y, X]),
                          [X = x-r, Y = y-s]
                        )
                      );
               lprp1 := -coeff(ltg1, y)*x+coeff(ltg1, x)*y+K1:
               for i to nops(sol1) do
                   Pedal||i := rhs~( solve
                                     ( eval
                                       ( [ ltg1,
                                           eval
                                           ( lprp1,
                                             [ K1 = solve
                                                    ( eval
                                                      ( lprp1,
                                                        [x = xp, y = yp]
                                                      ),
                                                      K1
                                                    )
                                            ]
                                           )
                                         ],
                                         s = eval(sol1[i], x = r)
                                       ),
                                       [x, y]
                                     )[]
                                   );
                    p9||i := plot( [Pedal||i[], r = -20 .. 20],
                                   colour = "MediumSeaGreen"
                   ):
               end do:
               return seq( p9||i, i=1..nops(sol1));
         end proc:

  Pedal2:=Pedal(C, xp1, yp1);

  plots:-display( [ p21, Pedal2 ],
                  size = [600, 600],
                  scaling = constrained,
                  caption = " Curve and it's Pedal curve"
                );

INTERFACE_PLOT(CURVES(Matrix(42, 2, {(1, 1) = -.5856122833767982, (1, 2) = 1.0583520400461186, (2, 1) = -.5293112556027565, (2, 2) = 1.0443605086884051, (3, 1) = -.4977354662214434, (3, 2) = 1.0375644499610743, (4, 1) = -.45268472978444296, (4, 2) = 1.0290736655227228, (5, 1) = -.41831931357811614, (5, 2) = 1.0234891906973458, (6, 1) = -.3646060192470982, (6, 2) = 1.0161909912710856, (7, 1) = -.3218317381434526, (7, 2) = 1.0115321895633884, (8, 1) = -.25375184679074636, (8, 2) = 1.006012227937065, (9, 1) = -.19929297502933477, (9, 2) = 1.0030770135594755, (10, 1) = -.11953249313963155, (10, 2) = 1.0007266873703178, (11, 1) = -0.55773204002072495e-1, (11, 2) = 1.0000801107971224, (12, 1) = 0.4254395664189193e-1, (12, 2) = .9999588548513489, (13, 1) = .12288687310141076, (13, 2) = .9988582178174505, (14, 1) = .18700144998836485, (14, 2) = .9954179916243527, (15, 1) = .23504404564746803, (15, 2) = .9898490977667705, (16, 1) = .28343797919616376, (16, 2) = .9798879148549685, (17, 1) = .3185180045247851, (17, 2) = .9685696745564574, (18, 1) = .35476918966750187, (18, 2) = .9516980711358027, (19, 1) = .38567497605492834, (19, 2) = .9317580896569475, (20, 1) = .4109759468805118, (20, 2) = .9106157906276997, (21, 1) = .4375672704018086, (21, 2) = .8828484157395434, (22, 1) = .46305903423793016, (22, 2) = .8503251147758538, (23, 1) = .4878871397649733, (23, 2) = .8129982707304924, (24, 1) = .5110920422816685, (24, 2) = .7735115535908411, (25, 1) = .5360702148013868, (25, 2) = .7270571818421695, (26, 1) = .56392737719862, (26, 2) = .6721302033382127, (27, 1) = .5951550537695117, (27, 2) = .6090090385981315, (28, 1) = .6132183832855264, (28, 2) = .5726075184818918, (29, 1) = .6331645991501407, (29, 2) = .5329769953143533, (30, 1) = .6527511397490542, (30, 2) = .4949062261274741, (31, 1) = .6748135274803231, (31, 2) = .4532457905514316, (32, 1) = .7036792630146106, (32, 2) = .40091555224405245, (33, 1) = .7387935625685268, (33, 2) = .3407389399150172, (34, 1) = .7599210717975061, (34, 2) = .30637117220689586, (35, 1) = .7845303897203115, (35, 2) = .26803698657506503, (36, 1) = .8143279016570615, (36, 2) = .223977411787599, (37, 1) = .8530709718617946, (37, 2) = .1703497216025437, (38, 1) = .8777275095494316, (38, 2) = .13825466416632867, (39, 1) = .9109036215419022, (39, 2) = 0.974209649516005e-1, (40, 1) = .9348663561184534, (40, 2) = 0.695234729053464e-1, (41, 1) = .981474290808697, (41, 2) = 0.18872143464226665e-1, (42, 1) = undefined, (42, 2) = undefined}, datatype = float[8])), COLOUR(RGB, .23529412, .70196078, .44313725), AXESLABELS("", ""), VIEW(DEFAULT, DEFAULT)), INTERFACE_PLOT(CURVES(Matrix(48, 2, {(1, 1) = 1.1705145945221005, (1, 2) = 1.898736454693393, (2, 1) = 1.2682931293077933, (2, 2) = 1.832348379927813, (3, 1) = 1.321449535516364, (3, 2) = 1.79343851601647, (4, 1) = 1.3952734454961482, (4, 2) = 1.735812327558924, (5, 1) = 1.4500237630456927, (5, 2) = 1.690159285818865, (6, 1) = 1.5329170629435593, (6, 2) = 1.6157948887556828, (7, 1) = 1.5965831266662487, (7, 2) = 1.5538742186752081, (8, 1) = 1.6489083743795685, (8, 2) = 1.4994335332993236, (9, 1) = 1.6935295059249391, (9, 2) = 1.4501624462458411, (10, 1) = 1.7324793605994528, (10, 2) = 1.4047583310584522, (11, 1) = 1.7670302703505287, (11, 2) = 1.3623992437799277, (12, 1) = 1.821637855618769, (12, 2) = 1.2908875038364904, (13, 1) = 1.8676230026713292, (13, 2) = 1.225576285363834, (14, 1) = 1.9070513837197491, (14, 2) = 1.165090912344009, (15, 1) = 1.941276124509136, (15, 2) = 1.1085199789493447, (16, 1) = 1.9969920423084315, (16, 2) = 1.0059890007192032, (17, 1) = 2.0406517542598688, (17, 2) = .9130628196977703, (18, 1) = 2.077211304328439, (18, 2) = .8220799136911057, (19, 1) = 2.10552064993331, (19, 2) = .7381526056651883, (20, 1) = 2.1270785020303995, (20, 2) = .6603229189535278, (21, 1) = 2.14304828988629, (21, 2) = .58759188843832, (22, 1) = 2.160153701531862, (22, 2) = .467976748643564, (23, 1) = 2.164857132962436, (23, 2) = .34168598906573194, (24, 1) = 2.158252951836966, (24, 2) = .24697170726266748, (25, 1) = 2.140328954647336, (25, 2) = .14731562170677812, (26, 1) = 2.114307635603691, (26, 2) = 0.623447345137431e-1, (27, 1) = 2.0844986751482772, (27, 2) = -0.5751251642093882e-2, (28, 1) = 2.0441624858277643, (28, 2) = -0.7400407885432994e-1, (29, 1) = 1.9966871774673234, (29, 2) = -.13406368562848103, (30, 1) = 1.94281045581185, (30, 2) = -.18529493851890466, (31, 1) = 1.8869614301263313, (31, 2) = -.2250567397948405, (32, 1) = 1.8229551553123193, (32, 2) = -.2580461268990225, (33, 1) = 1.7496515450658623, (33, 2) = -.2827382244704537, (34, 1) = 1.6684305613041268, (34, 2) = -.2966344961349515, (35, 1) = 1.5745214143238402, (35, 2) = -.29758668205134425, (36, 1) = 1.5289731081373263, (36, 2) = -.2927480050706648, (37, 1) = 1.4801687222296782, (37, 2) = -.28392954540643384, (38, 1) = 1.420297651035517, (38, 2) = -.26812150926911743, (39, 1) = 1.3532592130254228, (39, 2) = -.2440076977119881, (40, 1) = 1.3157683734280528, (40, 2) = -.22757750606967253, (41, 1) = 1.274576775240293, (41, 2) = -.2070714215553694, (42, 1) = 1.2279819936956045, (42, 2) = -.18073245321392922, (43, 1) = 1.1722305071109584, (43, 2) = -.14471979608891908, (44, 1) = 1.1393043137319774, (44, 2) = -.12107527518204395, (45, 1) = 1.097810799221357, (45, 2) = -0.8866823908328436e-1, (46, 1) = 1.0696715842945859, (46, 2) = -0.6497518904929551e-1, (47, 1) = 1.018875383002212, (47, 2) = -0.1852240849426758e-1, (48, 1) = undefined, (48, 2) = undefined}, datatype = float[8])), COLOUR(RGB, .23529412, .70196078, .44313725), AXESLABELS("", ""), VIEW(DEFAULT, DEFAULT)), INTERFACE_PLOT(CURVES(Matrix(68, 2, {(1, 1) = -.6466501785678163, (1, 2) = 1.0765088623952404, (2, 1) = -.7044692344842756, (2, 2) = 1.0969524079974413, (3, 1) = -.7375318100718412, (3, 2) = 1.110239473333194, (4, 1) = -.7634380877633185, (4, 2) = 1.1215486888192496, (5, 1) = -.7854597823607988, (5, 2) = 1.1318322857097398, (6, 1) = -.8049353922998106, (6, 2) = 1.1414767384335067, (7, 1) = -.8225693994592815, (7, 2) = 1.150684132554753, (8, 1) = -.8387868118432168, (8, 2) = 1.1595757641521864, (9, 1) = -.8538673736867111, (9, 2) = 1.1682311912458712, (10, 1) = -.868006755244192, (10, 2) = 1.1767059662814072, (11, 1) = -.8813481062288774, (11, 2) = 1.185040744418827, (12, 1) = -.893999831634766, (12, 2) = 1.193266395435267, (13, 1) = -.9060462994582937, (13, 2) = 1.2014070719715053, (14, 1) = -.917554639223471, (14, 2) = 1.2094821510897988, (15, 1) = -.9285792458484194, (15, 2) = 1.2175075166078375, (16, 1) = -.9391648698205592, (16, 2) = 1.2254964366359578, (17, 1) = -.9493488007263509, (17, 2) = 1.2334601823913118, (18, 1) = -.9591624492587759, (18, 2) = 1.241408475979587, (19, 1) = -.9686325183654653, (19, 2) = 1.2493498218121468, (20, 1) = -.9777818865947311, (20, 2) = 1.2572917568650643, (21, 1) = -.9866302853400948, (21, 2) = 1.2652410431087535, (22, 1) = -.9951948255577147, (22, 2) = 1.273203817949521, (23, 1) = -1.0034904126161295, (23, 2) = 1.281185713690735, (24, 1) = -1.0115300766736044, (24, 2) = 1.2891919538094099, (25, 1) = -1.0193252383479294, (25, 2) = 1.297227431675839, (26, 1) = -1.0268859241544324, (26, 2) = 1.3052967758466119, (27, 1) = -1.0342209424649402, (27, 2) = 1.3134044050120228, (28, 1) = -1.0413380280702282, (28, 2) = 1.3215545749309539, (29, 1) = -1.048243961492225, (29, 2) = 1.329751419148622, (30, 1) = -1.0549446677615857, (30, 2) = 1.3379989849000566, (31, 1) = -1.0614452983102727, (31, 2) = 1.3463012653148583, (32, 1) = -1.0672337226772282, (32, 2) = 1.3539651179857661, (33, 1) = -1.072860631715495, (33, 2) = 1.361681366281831, (34, 1) = -1.0783285418377322, (34, 2) = 1.3694530891670957, (35, 1) = -1.083639565180093, (35, 2) = 1.37728340063686, (36, 1) = -1.0887954297213573, (36, 2) = 1.3851754657414204, (37, 1) = -1.0937974952264462, (37, 2) = 1.3931325165944501, (38, 1) = -1.0986467653713632, (38, 2) = 1.4011578686069377, (39, 1) = -1.1033438963162552, (39, 2) = 1.4092549371856589, (40, 1) = -1.1078892019081505, (40, 2) = 1.4174272551376426, (41, 1) = -1.1122826556218133, (41, 2) = 1.4256784910339135, (42, 1) = -1.1165238892750289, (42, 2) = 1.4340124688035185, (43, 1) = -1.1206121884857576, (43, 2) = 1.4424331888553394, (44, 1) = -1.128325344079061, (44, 2) = 1.4595518799690694, (45, 1) = -1.135409092224611, (45, 2) = 1.4770710300570755, (46, 1) = -1.1418439623099033, (46, 2) = 1.4950316735694225, (47, 1) = -1.1476031803006792, (47, 2) = 1.5134806137595516, (48, 1) = -1.1526514153883989, (48, 2) = 1.532471974347552, (49, 1) = -1.156942996307816, (49, 2) = 1.5520692563298002, (50, 1) = -1.1604193759427908, (50, 2) = 1.572348134247669, (51, 1) = -1.1630054878215312, (51, 2) = 1.5934003621154684, (52, 1) = -1.164604403617457, (52, 2) = 1.615339396561193, (53, 1) = -1.1650892728679827, (53, 2) = 1.6383087786529167, (54, 1) = -1.1643100256825762, (54, 2) = 1.6621751351797953, (55, 1) = -1.1620570693438383, (55, 2) = 1.6874680765037948, (56, 1) = -1.1602839616977134, (56, 2) = 1.7007494643557517, (57, 1) = -1.1580133891599613, (57, 2) = 1.7145239900727265, (58, 1) = -1.1551808156159744, (58, 2) = 1.728859065680705, (59, 1) = -1.151704811048395, (59, 2) = 1.7438392838638164, (60, 1) = -1.1474802435087847, (60, 2) = 1.7595733154501463, (61, 1) = -1.1423674712820608, (61, 2) = 1.776204844872601, (62, 1) = -1.1361742247198152, (62, 2) = 1.7939308784900292, (63, 1) = -1.1286230416566323, (63, 2) = 1.8130346083453834, (64, 1) = -1.119287057250655, (64, 2) = 1.8339501277763848, (65, 1) = -1.107445788807485, (65, 2) = 1.8574075889547201, (66, 1) = -1.0916895235231396, (66, 2) = 1.8848308523241428, (67, 1) = -1.0683562099309785, (67, 2) = 1.9199062963711573, (68, 1) = undefined, (68, 2) = undefined}, datatype = float[8])), COLOUR(RGB, .23529412, .70196078, .44313725), AXESLABELS("", ""), VIEW(DEFAULT, DEFAULT)), INTERFACE_PLOT(CURVES(Matrix(76, 2, {(1, 1) = 1.059906468671845, (1, 2) = 1.9664026428650152, (2, 1) = .9502866626542085, (2, 2) = 2.0263387033863287, (3, 1) = .885257743276974, (3, 2) = 2.0587575606892576, (4, 1) = .8329943889699749, (4, 2) = 2.0831933363586885, (5, 1) = .7875924703991016, (5, 2) = 2.1032817212086226, (6, 1) = .7466397441446008, (6, 2) = 2.120511611737838, (7, 1) = .7088677549917043, (7, 2) = 2.135667390929035, (8, 1) = .6735116269217124, (8, 2) = 2.1492227047148202, (9, 1) = .6400679138202994, (9, 2) = 2.1614895902498295, (10, 1) = .6081842828981082, (10, 2) = 2.1726864966103845, (11, 1) = .5776026700324131, (11, 2) = 2.1829733755544027, (12, 1) = .548127278044593, (12, 2) = 2.1924714583910734, (13, 1) = .5196053118179567, (13, 2) = 2.2012751740361627, (14, 1) = .491914753466915, (14, 2) = 2.2094597191322336, (15, 1) = .4649562673256211, (15, 2) = 2.21708607515356, (16, 1) = .43864764756079816, (16, 2) = 2.2242044521501714, (17, 1) = .41291989531471335, (17, 2) = 2.230856723127004, (18, 1) = .387714376153232, (18, 2) = 2.2370781885419335, (19, 1) = .3629807147658573, (19, 2) = 2.2428988831126566, (20, 1) = .3386752055864611, (20, 2) = 2.248344561920324, (21, 1) = .3147595924315217, (21, 2) = 2.253437456783031, (22, 1) = .2912001172490915, (22, 2) = 2.258196864798543, (23, 1) = .26796676848193546, (23, 2) = 2.2626396121263594, (24, 1) = .24503267978833293, (24, 2) = 2.2667804235394766, (25, 1) = .22237364356384853, (25, 2) = 2.270632219778702, (26, 1) = .19996771319540568, (26, 2) = 2.2742063588516546, (27, 1) = .17779487464880556, (27, 2) = 2.2775128332710444, (28, 1) = .15583677276672186, (28, 2) = 2.28056043225205, (29, 1) = .1340764811082846, (29, 2) = 2.2833568757308504, (30, 1) = .11249830670465458, (30, 2) = 2.2859089254721607, (31, 1) = 0.9108762298907701e-1, (31, 2) = 2.288222477345742, (32, 1) = 0.7159158987544102e-1, (32, 2) = 2.290138561071377, (33, 1) = 0.5221486547984319e-1, (33, 2) = 2.2918618371484967, (34, 1) = 0.3294796864017522e-1, (34, 2) = 2.293395225400433, (35, 1) = 0.13781844621931308e-1, (35, 2) = 2.2947411952672234, (36, 1) = -0.24282516123956214e-1, (36, 2) = 2.2968786400182526, (37, 1) = -0.6204421973451923e-1, (37, 2) = 2.298285687089729, (38, 1) = -0.8083119371913043e-1, (38, 2) = 2.298717216582248, (39, 1) = -0.9956572408808925e-1, (39, 2) = 2.2989676803835395, (40, 1) = -.118255287126111, (40, 2) = 2.2990368086158024, (41, 1) = -.1369073024462478, (41, 2) = 2.2989239534856645, (42, 1) = -.17412832051234534, (42, 2) = 2.2981477645141357, (43, 1) = -.21128850730708595, (43, 2) = 2.296625997208774, (44, 1) = -.22986488147551998, (44, 2) = 2.295579547958926, (45, 1) = -.24844929914683353, (45, 2) = 2.2943385999714456, (46, 1) = -.2670499537492213, (46, 2) = 2.2928994195311474, (47, 1) = -.28567534820063706, (47, 2) = 2.291257708616107, (48, 1) = -.30433435963292, (48, 2) = 2.2894085534142685, (49, 1) = -.3230363124301118, (49, 2) = 2.287346362999205, (50, 1) = -.34179106154796834, (50, 2) = 2.2850647962810817, (51, 1) = -.3606090885544751, (51, 2) = 2.282556674851346, (52, 1) = -.37950161345372335, (52, 2) = 2.2798138786928455, (53, 1) = -.39848072618025027, (53, 2) = 2.276827220876351, (54, 1) = -.4175595427541302, (54, 2) = 2.2735862962320503, (55, 1) = -.4367523925787509, (55, 2) = 2.2700792974596733, (56, 1) = -.4560750454037224, (56, 2) = 2.26629279005959, (57, 1) = -.4755449893052073, (57, 2) = 2.26221143458764, (58, 1) = -.495181775017015, (58, 2) = 2.2578176406906083, (59, 1) = -.5150074476390814, (59, 2) = 2.2530911316006144, (60, 1) = -.534787675752838, (60, 2) = 2.2480761865822028, (61, 1) = -.5548041074185944, (61, 2) = 2.2426877301207893, (62, 1) = -.5750888767388106, (62, 2) = 2.236894729528627, (63, 1) = -.5956796913275031, (63, 2) = 2.2306603513318763, (64, 1) = -.6166213878548912, (64, 2) = 2.2239403822955497, (65, 1) = -.6379680859674682, (65, 2) = 2.2166810437409876, (66, 1) = -.6597862491515665, (66, 2) = 2.2088158873280657, (67, 1) = -.682159168753236, (67, 2) = 2.2002612510369994, (68, 1) = -.7051937751320275, (68, 2) = 2.19090936324526, (69, 1) = -.7290314484344602, (69, 2) = 2.180617408735659, (70, 1) = -.7538661395244016, (70, 2) = 2.1691892217570796, (71, 1) = -.7799769371689009, (71, 2) = 2.1563424235673825, (72, 1) = -.8077922806496194, (72, 2) = 2.1416437080487523, (73, 1) = -.8380341772511115, (73, 2) = 2.124363685324577, (74, 1) = -.8721138166999607, (74, 2) = 2.103079233412407, (75, 1) = -.9136946817785938, (75, 2) = 2.074104689483629, (76, 1) = undefined, (76, 2) = undefined}, datatype = float[8])), COLOUR(RGB, .23529412, .70196078, .44313725), AXESLABELS("", ""), VIEW(DEFAULT, DEFAULT))

 

 

``

NULL

``

NULL

Download pedCur.mw

will work - most of the time. So for your two examples, see the attached


 

rand1:=rand(2..9):
a:=rand1();
b:=rand1();
c:=rand1();
(a*sqrt(a*a^b))^(1/c);
simplify(%, power);

4

 

4

 

2

 

128^(1/2)

 

8*2^(1/2)

(1)

assume(x>0):
sqrt(x^3*x^(3/4));
simplify(%,power);

(x^(15/4))^(1/2)

 

x^(15/8)

(2)

 


 

Download pow.mw

As has already been stsated the problem of fitting experimental data to a "model" is a whole subject on its own. A lot depends on how complicated you want to get! It is probably worth trying a simple approach first.

The attached file is concepyually about as simple as you can get, it simply determines the parameters which will minimize the 'penalty' function

sum( (xmodel-xexp)^2+(ymodel-yexp)^2)

where the sum is taken over all points. It would be fairly trivial to rewrite the 'fitter' procdure in the solution module for any other penalty function, or to add a second model function to the solution module.

The only real drawback whcih I had was that the Optimization:-NLPSolve() command, and I had to use the DirectSearch() package which is free to download from the MapleSoft Applications Centre, and *seems* gernally to be a bit more robust. This does however eman that you will be unable ro re-execute the attached unless you have the DirectSearch() package loaded.


 

restart;
#
# Define a solution module
#
  solmod:= module()
                  option package;
                  export getXPData, getSol, fitter:
                  local ModuleLoad, XPData, DEsol:
           #
           # Use the ModuleLoad() as an initalisation
           # to
           #
           # 1) read the experimental data from an
           #    external file. (OP will have to change
           #    the file path
           # 2) set up the solution procedure for the
           #    ODE system
           #
                  ModuleLoad:=proc()
                                   uses ExcelTools;
                                   local fname:="C:/Users/TomLeslie/Desktop/XPdata.xlsx",
                                         M:=Import(fname,1,"A2"),
                                   g:=9.81,
                                   m:=0.25,
                                   ode:= { D(x__1)(t) = x__2(t),
                                           D(x__2)(t) = -Drag*sqrt(x__2(t)^2+x__4(t)^2)*x__2(t)/m,
                                           D(x__3)(t) = x__4(t),
                                           D(x__4)(t) = -g-Drag*sqrt(x__2(t)^2+x__4(t)^2)*x__4(t)/m
                                         },
                                   ics:= { x__1(0) = 0,
                                           x__2(0) = v__0*cos(alpha),
                                           x__3(0) = 0,
                                           x__4(0) = v__0*sin(alpha)
                                         },
                                   solution:=dsolve(`union`(ode,ics),
                                                     numeric,
                                                     parameters=[alpha, v__0, Drag],
                                                     events=[[x__3(t), halt]]):
                                   M[1,1]:=0;
                                   return M, solution;
                            end proc:
           #
           # Execute the ModuleLoad() to return the experimental
           # data and the parameterized ODE system
           #

                XPData, DEsol:= ModuleLoad();
           #
           # Define a procedure which returns a matrix containing
           # t, x(t) and y(t), from the ODE system model, for any
           # supplied set of parameters alpha, velocity and Drag
           #
                getSol:=proc( p1, p2, p3 )
                              local tstep:=1/30, ans, data__halt:
                              interface(warnlevel=0):
                              DEsol(parameters=[p1*Pi/180,p2,p3]);
                              data__halt:=DEsol(10);
                              interface(warnlevel=3):
                              ans:=Matrix( [ seq( rhs~(DEsol(j)),
                                                  j=0..rhs(data__halt[1]), tstep
                                                )
                                           ]
                                         );
                              return Matrix( [ans[..,1], ans[..,2], ans[..,4]], scan=rows);
                       end proc;
           #
           # Define a procedure which simply returns the experimental
           # data matrix
           #
                getXPData:=proc()
                                return XPData;
                           end proc;
           #
           # Define a 'fitter' procedure which calculates a
           # simple least-square difference between the
           # experimental data and that returned by solving
           # the ODE system for any supplied set of parameters
           # alpha, velocity and Drag
           #
                fitter:=proc( p1, p2, p3 )
                              local M:=getSol(p1, p2, p3):

                              add( (M[j,2]-XPData[j,2])^2,
                                   j=1..min(op([1,1],M),op([1,1],XPData))
                                 )
                              +
                              add( (M[j,3]-XPData[j,3])^2,
                                   j=1..min(op([1,1],M),op([1,1],XPData))
                                 );
                        end proc;
         end module:

#
# Instantiate the module, load the plots() package and
# defimne a plot function which is going to be used a
# few times
#
  with(solmod):
  with(plots):
  doPlot:=(dat, col)->pointplot( dat[..,2], dat[..,3],
                                 style=point,
                                 symbol=solidcircle,
                                 symbolsize=16,
                                 labels=[x-position, y-position],
                                 labelfont=[times, bold, 20],
                                 color=col
                               ):
 

#
# Get the solution from the ODE system for the
# supplied set of paramters and generate a plot
# of y-position against x-position
#
  res:=getSol(47, 11.5, 0.8450638480e-2):
  pA:=doPlot(res, red):
#
# Get the experimental data and generate a plot
# of y-position against x-position
#
  XP:=getXPData():
  pB:=doPlot(XP, blue):
#
# Display the experimental and model data on the
# same graph
#
  display([pA,pB]);
#
# Close but no coconut!
#

 

#
# Tried to use the 'fitter' procedure with NLPSolve
# to find 'best' values for angle, velocity and
# Drag, but this fails:-(
#
  Optimization:-NLPSolve(fitter, 40..60, 10..15, 0.5e-02..1.0e-01);

Error, (in Optimization:-NLPSolve) no improved point could be found

 

#
# Use the DirectSearch() package to obtain the best
# fit. This throws a couple of warnings, but *seems*
# to work
#
  fitPars:=DirectSearch:-Search( fitter,
                                 [p1=40..60, p2=10..15, p3=0.5e-02..1.0e-01]
                               );

Warning, initial point [p1 = .900000000000000, p2 = .900000000000000, p3 = .900000000000000] does not satisfy the inequality constraints; trying to find a feasible initial point

 

Warning, the new feasible initial point is [p1 = 46.7517737812633, p2 = 11.8882326721528, p3 = 0.979955380074218e-2]

 

[.19210558041243112, Vector(3, {(1) = 42.32561324590592, (2) = 11.574448061577609, (3) = 0.500000007987103e-2}), 207]

(1)

#
# Get the solution from the ODE with the values
# of parameters as returned by DirectSearch()
# and generate the plot of y-position versus
# x-position
#
  res:=getSol(convert(fitPars[2],list)[]):
  pA:=doPlot( res, red):
#
# Plot this solution agsainst that obtained for
# for the experimental data above
#
  plots:-display( [pA,pB],
                  title="Fitted Version",
                  titlefont=[times, bold, 20]);

 

 

NULL


 

Download projectile2.mw

If I check the "unknowns" prior to running the fsolve() command, then both 'f3' and 'Rsh' are reported as unknown. If I re-enter these with a simple copy+paste then hey presto, now they are 'known and the fsolve command works. Yet another clear cemonstration of twhy I wouldn't use 2D-input for a bet

If anyone can tell me the difference between the first and second assignments of 'Rsh' and 'f3' in the attached - I'd be vaguely interested. Or maybe I'll just stick to using 1D-input -which works

By the way, you don't really gain much for Digits settings higher than 20

restart; UseHardwareFloats := false; Digits := 40

false

 

40

(1)

q := 0.16021e-18

k := 0.13865e-22

NULL

Ns := 28

T := 273+27.82

Isc := 2.07

Voc := 19.45

Impp := 1.88

Vmpp := 15.32

Rsh := 326

dvdi := -1.52

Vt := n*k*T*Ns/q

NULL

f1 := Rs = -dvdi-Vt/(Io*exp(Voc/Vt))

f2 := Io = (Isc-Voc/Rsh)/(exp(Voc/Vt)-1)

f3 := Impp = Isc-Io*exp((Impp*Rs+Vmpp)/Vt)-(Impp*Rs+Vmpp)/Rsh

fsolve([f1, f2, f3], fulldigits); `union`(`~`[indets]([f1, f2, f3], 'name')[])

Error, (in fsolve) number of equations, 3, does not match number of variables, 5

 

{Io, Rs, Rsh, f3, n}

(2)

Rsh := 326; f3 := Impp = Isc-Io*exp((Impp*Rs+Vmpp)/Vt)-(Impp*Rs+Vmpp)/Rsh; `union`(`~`[indets]([f1, f2, f3], 'name')[]); fsolve([f1, f2, f3], fulldigits)

{Io, Rs, n}

 

{Io = 0.4431008008166232595833172837081272096103e-11, Rs = 1.159540176712161659423105533914104796216, n = .9941017332702008768221870425911358651381}

(3)

``


 

Download asoln.mw

Your "model" is only valid until the projectile hits the ground - calculation beyond this point is meaningless.

You can use the 'events' option to stop the solution process when the y-position is zero.

It is then trivial to populate a matrix with all required data from t=0 to the 'halt' time, with any step size you want.

Use this 'model' data to compare with your 'experimental' data. Precisely how you do this comparison is a whole other subject!!

See the attached

Throw with air resistance

 

restart

with(plots)``

NULL

Constants

g := 9.82; m := .250

alpha := 47*((1/180)*Pi); v__0 := 11.5

c__w := .47; rho := 1.2041; d := .195; A := (1/4)*Pi*d^2 = 0.2986476518e-1NULL

Drag := (1/2)*c__w*rho*A = 0.8450638480e-2NULL

 

 

System of ODE

x__1(t) is position in x-direction

x__2(t) is the velocity in x-direction

x__3(t) is position in y-direction

x__4(t) is the velocity in y-direction

 

ode1 := (D(x__1))(t) = x__2(t)

ode2 := (D(x__2))(t) = -Drag*sqrt(x__2(t)^2+x__4(t)^2)*x__2(t)/m

ode3 := (D(x__3))(t) = x__4(t)

ode4 := (D(x__4))(t) = -g-Drag*sqrt(x__2(t)^2+x__4(t)^2)*x__4(t)/m

``

odesystem := {ode1, ode2, ode3, ode4, x__1(0) = 0, x__2(0) = v__0*cos(alpha), x__3(0) = 0, x__4(0) = v__0*sin(alpha)}

solution := dsolve(odesystem, method = rkf45, numeric, range = 0 .. 3)

stil1 := color = red

odeplot(solution, [x__1(t), x__3(t), stil1], 0 .. 50, view = [0 .. 15, 0 .. 5], numpoints = 1200, scaling = constrained, size = [800, 500])

 

#
# Set up the ODE solution so that it "halts" when
# the projectile hits the ground - which occurs
# when the y-position ( ie x__3(t) ) is zero.
#
# The model is invalid beyond this time
#
  solution := dsolve(odesystem, numeric, events=[[x__3(t), halt]]):
  interface(warnlevel=0):
  data__halt:=solution(10);
  interface(warnlevel=3):
#
# Generate all data from this solution, in timesteps
# of tstep (OP seems to want 1/30) and store the
# results in a matrix whose columns are
#
#  t  x__1(t)  x__2(t)  x__3(t)  x__4(t)
#
# Note that the time of hitting the ground may not be
# be a multiple of the chosen time step (1/30), so
# data for the halt time (probably) won't be included
# in the output matrix, but is available from the
# variable data__halt
#
# "Model" data from this matrix can then be compared with
# "experimental" data in a variety of ways
#
  tstep:=1/30:
  ans:=Matrix( [ seq( rhs~(solution(j)),
                      j=0..rhs(data__halt[1]), tstep
                    )
               ]
             );
#
# As an illustration, plot the vertical position against
# the horizontal position using the points from the above
# matrix
#
  plots:-pointplot( ans[..,2], ans[..,4],
                    style=point,
                    symbol=solidcircle,
                    symbolsize=16,
                    labels=[x-position, y-position],
                    labelfont=[times, bold, 20],
                    color=red
                  );
#
# In case it makes things easier to compare with 'experimental'
# data, extract clumns from the above complete matrix, to
# produce another matrix containing only time t, x-position
# x__1(t) and y-position x__3(t)
#
  ans2:= Matrix( [ans[..,1], ans[..,2], ans[..,4]], scan=rows);
  

data__halt := [t = 1.57327929242181, x__1(t) = 10.0194885388110, x__2(t) = 5.20670616099533, x__3(t) = -3.64291929955129*10^(-17), x__4(t) = -7.20221849558883]

 

ans := Matrix(48, 5, {(1, 1) = HFloat(0.0), (1, 2) = HFloat(0.0), (1, 3) = HFloat(7.84298114071874), (1, 4) = HFloat(0.0), (1, 5) = HFloat(8.41056756862046), (2, 1) = 0.333333333333333e-1, (2, 2) = HFloat(0.25976493236922704), (2, 3) = HFloat(7.74368364726688), (2, 4) = HFloat(0.27313132626489567), (2, 5) = HFloat(7.9788155983275075), (3, 1) = 0.666666666666667e-1, (3, 2) = HFloat(0.5162953689172917), (3, 3) = HFloat(7.648867731230251), (3, 4) = HFloat(0.532017910338858), (3, 5) = HFloat(7.555784149767503), (4, 1) = .100000000000000, (4, 2) = HFloat(0.7697364179142934), (4, 3) = HFloat(7.55828071341947), (4, 4) = HFloat(0.776940694684087), (4, 5) = HFloat(7.14089762319472), (5, 1) = .133333333333333, (5, 2) = HFloat(1.0202250787430267), (5, 3) = HFloat(7.471684184880636), (5, 4) = HFloat(1.0081622612748506), (5, 5) = HFloat(6.733618195896751), (6, 1) = .166666666666667, (6, 2) = HFloat(1.267890549257393), (6, 3) = HFloat(7.388852633764783), (6, 4) = HFloat(1.2259275513703871), (6, 5) = HFloat(6.3334432804055725), (7, 1) = .200000000000000, (7, 2) = HFloat(1.5128547015782805), (7, 3) = HFloat(7.309572423308119), (7, 4) = HFloat(1.4304653984089686), (7, 5) = HFloat(5.939903631093076), (8, 1) = .233333333333333, (8, 2) = HFloat(1.7552325282678436), (8, 3) = HFloat(7.233639821983301), (8, 4) = HFloat(1.6219897942667023), (8, 5) = HFloat(5.552560050850399), (9, 1) = .266666666666667, (9, 2) = HFloat(1.9951323882901466), (9, 3) = HFloat(7.160859579948973), (9, 4) = HFloat(1.8007004530361885), (9, 5) = HFloat(5.171001166509253), (10, 1) = .300000000000000, (10, 2) = HFloat(2.2326561592077985), (10, 3) = HFloat(7.09104438455298), (10, 4) = HFloat(1.9667833489252986), (10, 5) = HFloat(4.794842768472781), (11, 1) = .333333333333333, (11, 2) = HFloat(2.467899633543875), (11, 3) = HFloat(7.02401401647495), (11, 4) = HFloat(2.120412399820355), (11, 5) = HFloat(4.423726273924407), (12, 1) = .366666666666667, (12, 2) = HFloat(2.7009527124851846), (12, 3) = HFloat(6.959593925301469), (12, 4) = HFloat(2.2617502510629564), (12, 5) = HFloat(4.057317079020092), (13, 1) = .400000000000000, (13, 2) = HFloat(2.931899623045857), (13, 3) = HFloat(6.897613794517017), (13, 4) = HFloat(2.390948935607624), (13, 5) = HFloat(3.6953031754781276), (14, 1) = .433333333333333, (14, 2) = HFloat(3.1608189207786497), (14, 3) = HFloat(6.837907527683807), (14, 4) = HFloat(2.5081498826605566), (14, 5) = HFloat(3.3373951365960277), (15, 1) = .466666666666667, (15, 2) = HFloat(3.3877836383187434), (15, 3) = HFloat(6.780312820061624), (15, 4) = HFloat(2.613484874217103), (15, 5) = HFloat(2.9833258333742196), (16, 1) = .500000000000000, (16, 2) = HFloat(3.6128614866894795), (16, 3) = HFloat(6.724670183452601), (16, 4) = HFloat(2.7070777147372658), (16, 5) = HFloat(2.6328492728174964), (17, 1) = .533333333333333, (17, 2) = HFloat(3.8361148922210053), (17, 3) = HFloat(6.670822531667672), (17, 4) = HFloat(2.7890445962839387), (17, 5) = HFloat(2.285740607217571), (18, 1) = .566666666666667, (18, 2) = HFloat(4.057601141485343), (18, 3) = HFloat(6.618614811802207), (18, 4) = HFloat(2.8594949225475927), (18, 5) = HFloat(1.9417962163351357), (19, 1) = .600000000000000, (19, 2) = HFloat(4.277372381661143), (19, 3) = HFloat(6.56789400332705), (19, 4) = HFloat(2.9185313110055784), (19, 5) = HFloat(1.6008337072116678), (20, 1) = .633333333333333, (20, 2) = HFloat(4.495475621801629), (20, 3) = HFloat(6.518509131747476), (20, 4) = HFloat(2.9662496077428187), (20, 5) = HFloat(1.2626919069167188), (21, 1) = .666666666666667, (21, 2) = HFloat(4.711952871405678), (21, 3) = HFloat(6.470312073808606), (21, 4) = HFloat(3.002740931206841), (21, 5) = HFloat(0.9272304056002928), (22, 1) = .700000000000000, (22, 2) = HFloat(4.9268411985745), (22, 3) = HFloat(6.423155559352822), (22, 4) = HFloat(3.0280927003195655), (22, 5) = HFloat(0.5943307028377451), (23, 1) = .733333333333333, (23, 2) = HFloat(5.140172928184175), (23, 3) = HFloat(6.376895420370412), (23, 4) = HFloat(3.042388954567959), (23, 5) = HFloat(0.2638953179422526), (24, 1) = .766666666666667, (24, 2) = HFloat(5.351975746247888), (24, 3) = HFloat(6.33139196184039), (24, 4) = HFloat(3.0457111962758723), (24, 5) = HFloat(-0.0641528922850923), (25, 1) = .800000000000000, (25, 2) = HFloat(5.562272699915908), (25, 3) = HFloat(6.286509961730498), (25, 4) = HFloat(3.0381383906040274), (25, 5) = HFloat(-0.3898707335552487), (26, 1) = .833333333333333, (26, 2) = HFloat(5.771082197475641), (26, 3) = HFloat(6.242118670997204), (26, 4) = HFloat(3.0197469655500315), (26, 5) = HFloat(-0.713294674091292), (27, 1) = .866666666666667, (27, 2) = HFloat(5.9784182115324525), (27, 3) = HFloat(6.198092327149759), (27, 4) = HFloat(2.9906117856777423), (27, 5) = HFloat(-1.0344417733414775), (28, 1) = .900000000000000, (28, 2) = HFloat(6.184290979540728), (28, 3) = HFloat(6.154311750544632), (28, 4) = HFloat(2.9508093805911835), (28, 5) = HFloat(-1.3533108876541973), (29, 1) = .933333333333333, (29, 2) = HFloat(6.3887068749692295), (29, 3) = HFloat(6.110664511162751), (29, 4) = HFloat(2.900416138376305), (29, 5) = HFloat(-1.6698828902608291), (30, 1) = .966666666666667, (30, 2) = HFloat(6.591668772369861), (30, 3) = HFloat(6.067046314435525), (30, 4) = HFloat(2.8395094605805693), (30, 5) = HFloat(-1.984124729004197), (31, 1) = 1., (31, 2) = HFloat(6.793176068884139), (31, 3) = HFloat(6.0233610648389675), (31, 4) = HFloat(2.7681678565936503), (31, 5) = HFloat(-2.2959895821349217), (32, 1) = 1.03333333333333, (32, 2) = HFloat(6.993224735711728), (32, 3) = HFloat(5.979520869988362), (32, 4) = HFloat(2.6864710297644967), (32, 5) = HFloat(-2.6054170585027614), (33, 1) = 1.06666666666667, (33, 2) = HFloat(7.1918082255366755), (33, 3) = HFloat(5.935446370522393), (33, 4) = HFloat(2.594501378547124), (33, 5) = HFloat(-2.912335948141717), (34, 1) = 1.10000000000000, (34, 2) = HFloat(7.38891763459238), (34, 3) = HFloat(5.891067107365091), (34, 4) = HFloat(2.4923439938299783), (34, 5) = HFloat(-3.216665281118206), (35, 1) = 1.13333333333333, (35, 2) = HFloat(7.584541884960813), (35, 3) = HFloat(5.846321173081986), (35, 4) = HFloat(2.380086718273864), (35, 5) = HFloat(-3.51831775150901), (36, 1) = 1.16666666666667, (36, 2) = HFloat(7.77866783729305), (36, 3) = HFloat(5.801155170982614), (36, 4) = HFloat(2.2578203199567763), (36, 5) = HFloat(-3.817200416110904), (37, 1) = 1.20000000000000, (37, 2) = HFloat(7.971280495403286), (37, 3) = HFloat(5.755523978509483), (37, 4) = HFloat(2.125638633823436), (37, 5) = HFloat(-4.1132154984219325), (38, 1) = 1.23333333333333, (38, 2) = HFloat(8.162363740708576), (38, 3) = HFloat(5.709390535211441), (38, 4) = HFloat(1.9836389848020595), (38, 5) = HFloat(-4.406261921108995), (39, 1) = 1.26666666666667, (39, 2) = HFloat(8.351900410075793), (39, 3) = HFloat(5.6627253804465045), (39, 4) = HFloat(1.8319220175532895), (39, 5) = HFloat(-4.696236783581304), (40, 1) = 1.30000000000000, (40, 2) = HFloat(8.539872526150651), (40, 3) = HFloat(5.615505718108064), (40, 4) = HFloat(1.6705918008397616), (40, 5) = HFloat(-4.983037887937312), (41, 1) = 1.33333333333333, (41, 2) = HFloat(8.726261305410626), (41, 3) = HFloat(5.567715398074769), (41, 4) = HFloat(1.4997558329256724), (41, 5) = HFloat(-5.266563792169967), (42, 1) = 1.36666666666667, (42, 2) = HFloat(8.911047277351281), (42, 3) = HFloat(5.519344661268784), (42, 4) = HFloat(1.3195250362597182), (42, 5) = HFloat(-5.546714192344312), (43, 1) = 1.40000000000000, (43, 2) = HFloat(9.094211029432726), (43, 3) = HFloat(5.470389335634566), (43, 4) = HFloat(1.1300136418925357), (43, 5) = HFloat(-5.823391335035323), (44, 1) = 1.43333333333333, (44, 2) = HFloat(9.275733155226563), (44, 3) = HFloat(5.420850899201273), (44, 4) = HFloat(0.931338951105114), (44, 5) = HFloat(-6.096500042839636), (45, 1) = 1.46666666666667, (45, 2) = HFloat(9.455594434923533), (45, 3) = HFloat(5.37073498372007), (45, 4) = HFloat(0.7236212632847577), (45, 5) = HFloat(-6.365949763305076), (46, 1) = 1.50000000000000, (46, 2) = HFloat(9.6337758648913), (46, 3) = HFloat(5.32005126165531), (46, 4) = HFloat(0.5069838744995208), (46, 5) = HFloat(-6.63165472813718), (47, 1) = 1.53333333333333, (47, 2) = HFloat(9.810258657674705), (47, 3) = HFloat(5.268813446184441), (47, 4) = HFloat(0.28155307749784036), (47, 5) = HFloat(-6.8935339531996584), (48, 1) = 1.56666666666667, (48, 2) = HFloat(9.985024364345932), (48, 3) = HFloat(5.217039135669473), (48, 4) = HFloat(0.0474580080118629), (48, 5) = HFloat(-7.151511310857042)})

 

 

ans2 := Matrix(48, 3, {(1, 1) = HFloat(0.0), (1, 2) = HFloat(0.0), (1, 3) = HFloat(0.0), (2, 1) = 0.333333333333333e-1, (2, 2) = HFloat(0.25976493236922704), (2, 3) = HFloat(0.27313132626489567), (3, 1) = 0.666666666666667e-1, (3, 2) = HFloat(0.5162953689172917), (3, 3) = HFloat(0.532017910338858), (4, 1) = .100000000000000, (4, 2) = HFloat(0.7697364179142934), (4, 3) = HFloat(0.776940694684087), (5, 1) = .133333333333333, (5, 2) = HFloat(1.0202250787430267), (5, 3) = HFloat(1.0081622612748506), (6, 1) = .166666666666667, (6, 2) = HFloat(1.267890549257393), (6, 3) = HFloat(1.2259275513703871), (7, 1) = .200000000000000, (7, 2) = HFloat(1.5128547015782805), (7, 3) = HFloat(1.4304653984089686), (8, 1) = .233333333333333, (8, 2) = HFloat(1.7552325282678436), (8, 3) = HFloat(1.6219897942667023), (9, 1) = .266666666666667, (9, 2) = HFloat(1.9951323882901466), (9, 3) = HFloat(1.8007004530361885), (10, 1) = .300000000000000, (10, 2) = HFloat(2.2326561592077985), (10, 3) = HFloat(1.9667833489252986), (11, 1) = .333333333333333, (11, 2) = HFloat(2.467899633543875), (11, 3) = HFloat(2.120412399820355), (12, 1) = .366666666666667, (12, 2) = HFloat(2.7009527124851846), (12, 3) = HFloat(2.2617502510629564), (13, 1) = .400000000000000, (13, 2) = HFloat(2.931899623045857), (13, 3) = HFloat(2.390948935607624), (14, 1) = .433333333333333, (14, 2) = HFloat(3.1608189207786497), (14, 3) = HFloat(2.5081498826605566), (15, 1) = .466666666666667, (15, 2) = HFloat(3.3877836383187434), (15, 3) = HFloat(2.613484874217103), (16, 1) = .500000000000000, (16, 2) = HFloat(3.6128614866894795), (16, 3) = HFloat(2.7070777147372658), (17, 1) = .533333333333333, (17, 2) = HFloat(3.8361148922210053), (17, 3) = HFloat(2.7890445962839387), (18, 1) = .566666666666667, (18, 2) = HFloat(4.057601141485343), (18, 3) = HFloat(2.8594949225475927), (19, 1) = .600000000000000, (19, 2) = HFloat(4.277372381661143), (19, 3) = HFloat(2.9185313110055784), (20, 1) = .633333333333333, (20, 2) = HFloat(4.495475621801629), (20, 3) = HFloat(2.9662496077428187), (21, 1) = .666666666666667, (21, 2) = HFloat(4.711952871405678), (21, 3) = HFloat(3.002740931206841), (22, 1) = .700000000000000, (22, 2) = HFloat(4.9268411985745), (22, 3) = HFloat(3.0280927003195655), (23, 1) = .733333333333333, (23, 2) = HFloat(5.140172928184175), (23, 3) = HFloat(3.042388954567959), (24, 1) = .766666666666667, (24, 2) = HFloat(5.351975746247888), (24, 3) = HFloat(3.0457111962758723), (25, 1) = .800000000000000, (25, 2) = HFloat(5.562272699915908), (25, 3) = HFloat(3.0381383906040274), (26, 1) = .833333333333333, (26, 2) = HFloat(5.771082197475641), (26, 3) = HFloat(3.0197469655500315), (27, 1) = .866666666666667, (27, 2) = HFloat(5.9784182115324525), (27, 3) = HFloat(2.9906117856777423), (28, 1) = .900000000000000, (28, 2) = HFloat(6.184290979540728), (28, 3) = HFloat(2.9508093805911835), (29, 1) = .933333333333333, (29, 2) = HFloat(6.3887068749692295), (29, 3) = HFloat(2.900416138376305), (30, 1) = .966666666666667, (30, 2) = HFloat(6.591668772369861), (30, 3) = HFloat(2.8395094605805693), (31, 1) = 1., (31, 2) = HFloat(6.793176068884139), (31, 3) = HFloat(2.7681678565936503), (32, 1) = 1.03333333333333, (32, 2) = HFloat(6.993224735711728), (32, 3) = HFloat(2.6864710297644967), (33, 1) = 1.06666666666667, (33, 2) = HFloat(7.1918082255366755), (33, 3) = HFloat(2.594501378547124), (34, 1) = 1.10000000000000, (34, 2) = HFloat(7.38891763459238), (34, 3) = HFloat(2.4923439938299783), (35, 1) = 1.13333333333333, (35, 2) = HFloat(7.584541884960813), (35, 3) = HFloat(2.380086718273864), (36, 1) = 1.16666666666667, (36, 2) = HFloat(7.77866783729305), (36, 3) = HFloat(2.2578203199567763), (37, 1) = 1.20000000000000, (37, 2) = HFloat(7.971280495403286), (37, 3) = HFloat(2.125638633823436), (38, 1) = 1.23333333333333, (38, 2) = HFloat(8.162363740708576), (38, 3) = HFloat(1.9836389848020595), (39, 1) = 1.26666666666667, (39, 2) = HFloat(8.351900410075793), (39, 3) = HFloat(1.8319220175532895), (40, 1) = 1.30000000000000, (40, 2) = HFloat(8.539872526150651), (40, 3) = HFloat(1.6705918008397616), (41, 1) = 1.33333333333333, (41, 2) = HFloat(8.726261305410626), (41, 3) = HFloat(1.4997558329256724), (42, 1) = 1.36666666666667, (42, 2) = HFloat(8.911047277351281), (42, 3) = HFloat(1.3195250362597182), (43, 1) = 1.40000000000000, (43, 2) = HFloat(9.094211029432726), (43, 3) = HFloat(1.1300136418925357), (44, 1) = 1.43333333333333, (44, 2) = HFloat(9.275733155226563), (44, 3) = HFloat(0.931338951105114), (45, 1) = 1.46666666666667, (45, 2) = HFloat(9.455594434923533), (45, 3) = HFloat(0.7236212632847577), (46, 1) = 1.50000000000000, (46, 2) = HFloat(9.6337758648913), (46, 3) = HFloat(0.5069838744995208), (47, 1) = 1.53333333333333, (47, 2) = HFloat(9.810258657674705), (47, 3) = HFloat(0.28155307749784036), (48, 1) = 1.56666666666667, (48, 2) = HFloat(9.985024364345932), (48, 3) = HFloat(0.0474580080118629)})

(1)

 

``

NULL

Download projectile.mw

 

MAple attempts to "protect" the user from the consequences of displaying *large* amounts of data. This "protection" can be overridden by setting the interface variable 'rtablesize', which is 10 by default. Although there is nothing wrong with mmcdara's solution, it will output any size of structured data - and if one of the dimensions happens to be 1000000, then you will get an awful lot of screenfuls of data. It is *probably* safer to stick with a "hard" limit as in the following where rtablesize is set to 30

        restart;
         with( DEtools ):
 with( plots ):
with( LinearAlgebra ):
interface(rtablesize=30):
ode2 := diff( x(t), t,t ) + diff( x(t), t ) - 2*x(t) = 0;

diff(diff(x(t), t), t)+diff(x(t), t)-2*x(t) = 0

(1)

ic2 := x(0)=X0, D(x)(0)=0;
ic3 := eval(ic2,X0=3);

x(0) = X0, (D(x))(0) = 0

 

x(0) = 3, (D(x))(0) = 0

(2)

        nsol := dsolve( {ode2,ic3}, x(t), type=numeric );

proc (x_rkf45) local _res, _dat, _vars, _solnproc, _xout, _ndsol, _pars, _n, _i; option `Copyright (c) 2000 by Waterloo Maple Inc. All rights reserved.`; if 1 < nargs then error "invalid input: too many arguments" end if; _EnvDSNumericSaveDigits := Digits; Digits := 15; if _EnvInFsolve = true then _xout := evalf[_EnvDSNumericSaveDigits](x_rkf45) else _xout := evalf(x_rkf45) end if; _dat := Array(1..4, {(1) = proc (_xin) local _xout, _dtbl, _dat, _vmap, _x0, _y0, _val, _dig, _n, _ne, _nd, _nv, _pars, _ini, _par, _i, _j, _k, _src; option `Copyright (c) 2002 by Waterloo Maple Inc. All rights reserved.`; table( [( "complex" ) = false ] ) _xout := _xin; _pars := []; _dtbl := array( 1 .. 4, [( 1 ) = (array( 1 .. 26, [( 1 ) = (datatype = float[8], order = C_order, storage = rectangular), ( 2 ) = (datatype = float[8], order = C_order, storage = rectangular), ( 3 ) = ([0, 0, 0, Array(1..0, 1..2, {}, datatype = float[8], order = C_order)]), ( 4 ) = (Array(1..63, {(1) = 2, (2) = 2, (3) = 0, (4) = 0, (5) = 0, (6) = 0, (7) = 1, (8) = 0, (9) = 0, (10) = 0, (11) = 0, (12) = 0, (13) = 0, (14) = 0, (15) = 0, (16) = 0, (17) = 0, (18) = 1, (19) = 30000, (20) = 0, (21) = 0, (22) = 1, (23) = 4, (24) = 0, (25) = 1, (26) = 15, (27) = 1, (28) = 0, (29) = 1, (30) = 3, (31) = 3, (32) = 0, (33) = 1, (34) = 0, (35) = 0, (36) = 0, (37) = 0, (38) = 0, (39) = 0, (40) = 0, (41) = 0, (42) = 0, (43) = 1, (44) = 0, (45) = 0, (46) = 0, (47) = 0, (48) = 0, (49) = 0, (50) = 50, (51) = 1, (52) = 0, (53) = 0, (54) = 0, (55) = 0, (56) = 0, (57) = 0, (58) = 0, (59) = 10000, (60) = 0, (61) = 1000, (62) = 0, (63) = 0}, datatype = integer[8])), ( 5 ) = (Array(1..28, {(1) = .0, (2) = 0.10e-5, (3) = .0, (4) = 0.500001e-14, (5) = .0, (6) = 0.8412764593069243e-3, (7) = .0, (8) = 0.10e-5, (9) = .0, (10) = .0, (11) = .0, (12) = .0, (13) = 1.0, (14) = .0, (15) = .49999999999999, (16) = .0, (17) = 1.0, (18) = 1.0, (19) = .0, (20) = .0, (21) = 1.0, (22) = 1.0, (23) = .0, (24) = .0, (25) = 0.10e-14, (26) = .0, (27) = .0, (28) = .0}, datatype = float[8], order = C_order)), ( 6 ) = (Array(1..2, {(1) = 3.0, (2) = .0}, datatype = float[8], order = C_order)), ( 7 ) = ([Array(1..4, 1..7, {(1, 1) = .0, (1, 2) = .203125, (1, 3) = .3046875, (1, 4) = .75, (1, 5) = .8125, (1, 6) = .40625, (1, 7) = .8125, (2, 1) = 0.6378173828125e-1, (2, 2) = .0, (2, 3) = .279296875, (2, 4) = .27237892150878906, (2, 5) = -0.9686851501464844e-1, (2, 6) = 0.1956939697265625e-1, (2, 7) = .5381584167480469, (3, 1) = 0.31890869140625e-1, (3, 2) = .0, (3, 3) = -.34375, (3, 4) = -.335235595703125, (3, 5) = .2296142578125, (3, 6) = .41748046875, (3, 7) = 11.480712890625, (4, 1) = 0.9710520505905151e-1, (4, 2) = .0, (4, 3) = .40350341796875, (4, 4) = 0.20297467708587646e-1, (4, 5) = -0.6054282188415527e-2, (4, 6) = -0.4770040512084961e-1, (4, 7) = .77858567237854}, datatype = float[8], order = C_order), Array(1..6, 1..6, {(1, 1) = .0, (1, 2) = .0, (1, 3) = .0, (1, 4) = .0, (1, 5) = .0, (1, 6) = 1.0, (2, 1) = .25, (2, 2) = .0, (2, 3) = .0, (2, 4) = .0, (2, 5) = .0, (2, 6) = 1.0, (3, 1) = .1875, (3, 2) = .5625, (3, 3) = .0, (3, 4) = .0, (3, 5) = .0, (3, 6) = 2.0, (4, 1) = .23583984375, (4, 2) = -.87890625, (4, 3) = .890625, (4, 4) = .0, (4, 5) = .0, (4, 6) = .2681884765625, (5, 1) = .1272735595703125, (5, 2) = -.5009765625, (5, 3) = .44921875, (5, 4) = -0.128936767578125e-1, (5, 5) = .0, (5, 6) = 0.626220703125e-1, (6, 1) = -0.927734375e-1, (6, 2) = .626220703125, (6, 3) = -.4326171875, (6, 4) = .1418304443359375, (6, 5) = -0.861053466796875e-1, (6, 6) = .3131103515625}, datatype = float[8], order = C_order), Array(1..6, {(1) = .0, (2) = .386, (3) = .21, (4) = .63, (5) = 1.0, (6) = 1.0}, datatype = float[8], order = C_order), Array(1..6, {(1) = .25, (2) = -.1043, (3) = .1035, (4) = -0.362e-1, (5) = .0, (6) = .0}, datatype = float[8], order = C_order), Array(1..6, 1..5, {(1, 1) = .0, (1, 2) = .0, (1, 3) = .0, (1, 4) = .0, (1, 5) = .0, (2, 1) = 1.544, (2, 2) = .0, (2, 3) = .0, (2, 4) = .0, (2, 5) = .0, (3, 1) = .9466785280815533, (3, 2) = .25570116989825814, (3, 3) = .0, (3, 4) = .0, (3, 5) = .0, (4, 1) = 3.3148251870684886, (4, 2) = 2.896124015972123, (4, 3) = .9986419139977808, (4, 4) = .0, (4, 5) = .0, (5, 1) = 1.2212245092262748, (5, 2) = 6.019134481287752, (5, 3) = 12.537083329320874, (5, 4) = -.687886036105895, (5, 5) = .0, (6, 1) = 1.2212245092262748, (6, 2) = 6.019134481287752, (6, 3) = 12.537083329320874, (6, 4) = -.687886036105895, (6, 5) = 1.0}, datatype = float[8], order = C_order), Array(1..6, 1..5, {(1, 1) = .0, (1, 2) = .0, (1, 3) = .0, (1, 4) = .0, (1, 5) = .0, (2, 1) = -5.6688, (2, 2) = .0, (2, 3) = .0, (2, 4) = .0, (2, 5) = .0, (3, 1) = -2.4300933568337584, (3, 2) = -.20635991570891224, (3, 3) = .0, (3, 4) = .0, (3, 5) = .0, (4, 1) = -.10735290581452621, (4, 2) = -9.594562251021896, (4, 3) = -20.470286148096154, (4, 4) = .0, (4, 5) = .0, (5, 1) = 7.496443313968615, (5, 2) = -10.246804314641219, (5, 3) = -33.99990352819906, (5, 4) = 11.708908932061595, (5, 5) = .0, (6, 1) = 8.083246795922411, (6, 2) = -7.981132988062785, (6, 3) = -31.52159432874373, (6, 4) = 16.319305431231363, (6, 5) = -6.0588182388340535}, datatype = float[8], order = C_order), Array(1..3, 1..5, {(1, 1) = .0, (1, 2) = .0, (1, 3) = .0, (1, 4) = .0, (1, 5) = .0, (2, 1) = 10.126235083446911, (2, 2) = -7.487995877607633, (2, 3) = -34.800918615557414, (2, 4) = -7.9927717075687275, (2, 5) = 1.0251377232956207, (3, 1) = -.6762803392806898, (3, 2) = 6.087714651678606, (3, 3) = 16.43084320892463, (3, 4) = 24.767225114183653, (3, 5) = -6.5943891257167815}, datatype = float[8], order = C_order)]), ( 9 ) = ([Array(1..2, {(1) = .1, (2) = .1}, datatype = float[8], order = C_order), Array(1..2, {(1) = .0, (2) = .0}, datatype = float[8], order = C_order), Array(1..2, {(1) = .0, (2) = .0}, datatype = float[8], order = C_order), Array(1..2, {(1) = .0, (2) = .0}, datatype = float[8], order = C_order), Array(1..2, {(1) = .0, (2) = .0}, datatype = float[8], order = C_order), Array(1..2, 1..2, {(1, 1) = .0, (1, 2) = .0, (2, 1) = .0, (2, 2) = .0}, datatype = float[8], order = C_order), Array(1..2, 1..2, {(1, 1) = .0, (1, 2) = .0, (2, 1) = .0, (2, 2) = .0}, datatype = float[8], order = C_order), Array(1..2, 1..6, {(1, 1) = .0, (1, 2) = .0, (1, 3) = .0, (1, 4) = .0, (1, 5) = .0, (1, 6) = .0, (2, 1) = .0, (2, 2) = .0, (2, 3) = .0, (2, 4) = .0, (2, 5) = .0, (2, 6) = .0}, datatype = float[8], order = C_order), Array(1..2, {(1) = 0, (2) = 0}, datatype = integer[8]), Array(1..2, {(1) = .0, (2) = .0}, datatype = float[8], order = C_order), Array(1..2, {(1) = .0, (2) = .0}, datatype = float[8], order = C_order), Array(1..2, {(1) = .0, (2) = .0}, datatype = float[8], order = C_order), Array(1..2, {(1) = .0, (2) = .0}, datatype = float[8], order = C_order), Array(1..2, {(1) = .0, (2) = .0}, datatype = float[8], order = C_order), Array(1..4, {(1) = .0, (2) = .0, (3) = .0, (4) = .0}, datatype = float[8], order = C_order)]), ( 8 ) = ([Array(1..2, {(1) = 3.0, (2) = .0}, datatype = float[8], order = C_order), Array(1..2, {(1) = .0, (2) = .0}, datatype = float[8], order = C_order), Array(1..2, {(1) = .0, (2) = 6.0}, datatype = float[8], order = C_order), 0, 0]), ( 11 ) = (Array(1..6, 0..2, {(1, 1) = .0, (1, 2) = .0, (2, 0) = .0, (2, 1) = .0, (2, 2) = .0, (3, 0) = .0, (3, 1) = .0, (3, 2) = .0, (4, 0) = .0, (4, 1) = .0, (4, 2) = .0, (5, 0) = .0, (5, 1) = .0, (5, 2) = .0, (6, 0) = .0, (6, 1) = .0, (6, 2) = .0}, datatype = float[8], order = C_order)), ( 10 ) = ([proc (N, X, Y, YP) option `[Y[1] = x(t), Y[2] = diff(x(t),t)]`; YP[2] := -Y[2]+2*Y[1]; YP[1] := Y[2]; 0 end proc, -1, 0, 0, 0, 0, 0, 0]), ( 13 ) = (), ( 12 ) = (), ( 15 ) = ("rkf45"), ( 14 ) = ([0, 0]), ( 18 ) = ([]), ( 19 ) = (0), ( 16 ) = ([0, 0, 0, []]), ( 17 ) = ([proc (N, X, Y, YP) option `[Y[1] = x(t), Y[2] = diff(x(t),t)]`; YP[2] := -Y[2]+2*Y[1]; YP[1] := Y[2]; 0 end proc, -1, 0, 0, 0, 0, 0, 0]), ( 22 ) = (0), ( 23 ) = (0), ( 20 ) = ([]), ( 21 ) = (0), ( 26 ) = (Array(1..0, {})), ( 25 ) = (Array(1..0, {})), ( 24 ) = (0)  ] ))  ] ); _y0 := Array(0..2, {(1) = 0., (2) = 3.}); _vmap := array( 1 .. 2, [( 1 ) = (1), ( 2 ) = (2)  ] ); _x0 := _dtbl[1][5][5]; _n := _dtbl[1][4][1]; _ne := _dtbl[1][4][3]; _nd := _dtbl[1][4][4]; _nv := _dtbl[1][4][16]; if not type(_xout, 'numeric') then if member(_xout, ["start", "left", "right"]) then if _Env_smart_dsolve_numeric = true or _dtbl[1][4][10] = 1 then if _xout = "left" then if type(_dtbl[2], 'table') then return _dtbl[2][5][1] end if elif _xout = "right" then if type(_dtbl[3], 'table') then return _dtbl[3][5][1] end if end if end if; return _dtbl[1][5][5] elif _xout = "method" then return _dtbl[1][15] elif _xout = "storage" then return evalb(_dtbl[1][4][10] = 1) elif _xout = "leftdata" then if not type(_dtbl[2], 'array') then return NULL else return eval(_dtbl[2]) end if elif _xout = "rightdata" then if not type(_dtbl[3], 'array') then return NULL else return eval(_dtbl[3]) end if elif _xout = "enginedata" then return eval(_dtbl[1]) elif _xout = "enginereset" then _dtbl[2] := evaln(_dtbl[2]); _dtbl[3] := evaln(_dtbl[3]); return NULL elif _xout = "initial" then return procname(_y0[0]) elif _xout = "laxtol" then return _dtbl[`if`(member(_dtbl[4], {2, 3}), _dtbl[4], 1)][5][18] elif _xout = "numfun" then return `if`(member(_dtbl[4], {2, 3}), _dtbl[_dtbl[4]][4][18], 0) elif _xout = "parameters" then return [seq(_y0[_n+_i], _i = 1 .. nops(_pars))] elif _xout = "initial_and_parameters" then return procname(_y0[0]), [seq(_y0[_n+_i], _i = 1 .. nops(_pars))] elif _xout = "last" then if _dtbl[4] <> 2 and _dtbl[4] <> 3 or _x0-_dtbl[_dtbl[4]][5][1] = 0. then error "no information is available on last computed point" else _xout := _dtbl[_dtbl[4]][5][1] end if elif _xout = "function" then if _dtbl[1][4][33]-2. = 0 then return eval(_dtbl[1][10], 1) else return eval(_dtbl[1][10][1], 1) end if elif _xout = "map" then return copy(_vmap) elif type(_xin, `=`) and type(rhs(_xin), 'list') and member(lhs(_xin), {"initial", "parameters", "initial_and_parameters"}) then _ini, _par := [], []; if lhs(_xin) = "initial" then _ini := rhs(_xin) elif lhs(_xin) = "parameters" then _par := rhs(_xin) elif select(type, rhs(_xin), `=`) <> [] then _par, _ini := selectremove(type, rhs(_xin), `=`) elif nops(rhs(_xin)) < nops(_pars)+1 then error "insufficient data for specification of initial and parameters" else _par := rhs(_xin)[-nops(_pars) .. -1]; _ini := rhs(_xin)[1 .. -nops(_pars)-1] end if; _xout := lhs(_xout); if _par <> [] then `dsolve/numeric/process_parameters`(_n, _pars, _par, _y0) end if; if _ini <> [] then `dsolve/numeric/process_initial`(_n-_ne, _ini, _y0, _pars, _vmap) end if; `dsolve/numeric/SC/reinitialize`(_dtbl, _y0, _n, procname, _pars); if _Env_smart_dsolve_numeric = true and type(_y0[0], 'numeric') and _dtbl[1][4][10] <> 1 then procname("right") := _y0[0]; procname("left") := _y0[0] end if; if _xout = "initial" then return [_y0[0], seq(_y0[_vmap[_i]], _i = 1 .. _n-_ne)] elif _xout = "parameters" then return [seq(_y0[_n+_i], _i = 1 .. nops(_pars))] else return [_y0[0], seq(_y0[_vmap[_i]], _i = 1 .. _n-_ne)], [seq(_y0[_n+_i], _i = 1 .. nops(_pars))] end if elif _xin = "eventstop" then if _nv = 0 then error "this solution has no events" end if; _i := _dtbl[4]; if _i <> 2 and _i <> 3 then return 0 end if; if _dtbl[_i][4][10] = 1 and assigned(_dtbl[5-_i]) and _dtbl[_i][4][9] < 100 and 100 <= _dtbl[5-_i][4][9] then _i := 5-_i; _dtbl[4] := _i; _j := round(_dtbl[_i][4][17]); return round(_dtbl[_i][3][1][_j, 1]) elif 100 <= _dtbl[_i][4][9] then _j := round(_dtbl[_i][4][17]); return round(_dtbl[_i][3][1][_j, 1]) else return 0 end if elif _xin = "eventstatus" then if _nv = 0 then error "this solution has no events" end if; _i := [selectremove(proc (a) options operator, arrow; _dtbl[1][3][1][a, 7] = 1 end proc, {seq(_j, _j = 1 .. round(_dtbl[1][3][1][_nv+1, 1]))})]; return ':-enabled' = _i[1], ':-disabled' = _i[2] elif _xin = "eventclear" then if _nv = 0 then error "this solution has no events" end if; _i := _dtbl[4]; if _i <> 2 and _i <> 3 then error "no events to clear" end if; if _dtbl[_i][4][10] = 1 and assigned(_dtbl[5-_i]) and _dtbl[_i][4][9] < 100 and 100 < _dtbl[5-_i][4][9] then _dtbl[4] := 5-_i; _i := 5-_i end if; if _dtbl[_i][4][9] < 100 then error "no events to clear" elif _nv < _dtbl[_i][4][9]-100 then error "event error condition cannot be cleared" else _j := _dtbl[_i][4][9]-100; if irem(round(_dtbl[_i][3][1][_j, 4]), 2) = 1 then error "retriggerable events cannot be cleared" end if; _j := round(_dtbl[_i][3][1][_j, 1]); for _k to _nv do if _dtbl[_i][3][1][_k, 1] = _j then if _dtbl[_i][3][1][_k, 2] = 3 then error "range events cannot be cleared" end if; _dtbl[_i][3][1][_k, 8] := _dtbl[_i][3][1][_nv+1, 8] end if end do; _dtbl[_i][4][17] := 0; _dtbl[_i][4][9] := 0; if _dtbl[1][4][10] = 1 then if _i = 2 then try procname(procname("left")) catch:  end try else try procname(procname("right")) catch:  end try end if end if end if; return  elif type(_xin, `=`) and member(lhs(_xin), {"eventdisable", "eventenable"}) then if _nv = 0 then error "this solution has no events" end if; if type(rhs(_xin), {('list')('posint'), ('set')('posint')}) then _i := {op(rhs(_xin))} elif type(rhs(_xin), 'posint') then _i := {rhs(_xin)} else error "event identifiers must be integers in the range 1..%1", round(_dtbl[1][3][1][_nv+1, 1]) end if; if select(proc (a) options operator, arrow; _nv < a end proc, _i) <> {} then error "event identifiers must be integers in the range 1..%1", round(_dtbl[1][3][1][_nv+1, 1]) end if; _k := {}; for _j to _nv do if member(round(_dtbl[1][3][1][_j, 1]), _i) then _k := `union`(_k, {_j}) end if end do; _i := _k; if lhs(_xin) = "eventdisable" then _dtbl[4] := 0; _j := [evalb(assigned(_dtbl[2]) and member(_dtbl[2][4][17], _i)), evalb(assigned(_dtbl[3]) and member(_dtbl[3][4][17], _i))]; for _k in _i do _dtbl[1][3][1][_k, 7] := 0; if assigned(_dtbl[2]) then _dtbl[2][3][1][_k, 7] := 0 end if; if assigned(_dtbl[3]) then _dtbl[3][3][1][_k, 7] := 0 end if end do; if _j[1] then for _k to _nv+1 do if _k <= _nv and not type(_dtbl[2][3][4][_k, 1], 'undefined') then userinfo(3, {'events', 'eventreset'}, `reinit #2, event code `, _k, ` to defined init `, _dtbl[2][3][4][_k, 1]); _dtbl[2][3][1][_k, 8] := _dtbl[2][3][4][_k, 1] elif _dtbl[2][3][1][_k, 2] = 0 and irem(iquo(round(_dtbl[2][3][1][_k, 4]), 32), 2) = 1 then userinfo(3, {'events', 'eventreset'}, `reinit #2, event code `, _k, ` to rate hysteresis init `, _dtbl[2][5][24]); _dtbl[2][3][1][_k, 8] := _dtbl[2][5][24] elif _dtbl[2][3][1][_k, 2] = 0 and irem(iquo(round(_dtbl[2][3][1][_k, 4]), 2), 2) = 0 then userinfo(3, {'events', 'eventreset'}, `reinit #2, event code `, _k, ` to initial init `, _x0); _dtbl[2][3][1][_k, 8] := _x0 else userinfo(3, {'events', 'eventreset'}, `reinit #2, event code `, _k, ` to fireinitial init `, _x0-1); _dtbl[2][3][1][_k, 8] := _x0-1 end if end do; _dtbl[2][4][17] := 0; _dtbl[2][4][9] := 0; if _dtbl[1][4][10] = 1 then procname(procname("left")) end if end if; if _j[2] then for _k to _nv+1 do if _k <= _nv and not type(_dtbl[3][3][4][_k, 2], 'undefined') then userinfo(3, {'events', 'eventreset'}, `reinit #3, event code `, _k, ` to defined init `, _dtbl[3][3][4][_k, 2]); _dtbl[3][3][1][_k, 8] := _dtbl[3][3][4][_k, 2] elif _dtbl[3][3][1][_k, 2] = 0 and irem(iquo(round(_dtbl[3][3][1][_k, 4]), 32), 2) = 1 then userinfo(3, {'events', 'eventreset'}, `reinit #3, event code `, _k, ` to rate hysteresis init `, _dtbl[3][5][24]); _dtbl[3][3][1][_k, 8] := _dtbl[3][5][24] elif _dtbl[3][3][1][_k, 2] = 0 and irem(iquo(round(_dtbl[3][3][1][_k, 4]), 2), 2) = 0 then userinfo(3, {'events', 'eventreset'}, `reinit #3, event code `, _k, ` to initial init `, _x0); _dtbl[3][3][1][_k, 8] := _x0 else userinfo(3, {'events', 'eventreset'}, `reinit #3, event code `, _k, ` to fireinitial init `, _x0+1); _dtbl[3][3][1][_k, 8] := _x0+1 end if end do; _dtbl[3][4][17] := 0; _dtbl[3][4][9] := 0; if _dtbl[1][4][10] = 1 then procname(procname("right")) end if end if else for _k in _i do _dtbl[1][3][1][_k, 7] := 1 end do; _dtbl[2] := evaln(_dtbl[2]); _dtbl[3] := evaln(_dtbl[3]); _dtbl[4] := 0; if _dtbl[1][4][10] = 1 then if _x0 <= procname("right") then try procname(procname("right")) catch:  end try end if; if procname("left") <= _x0 then try procname(procname("left")) catch:  end try end if end if end if; return  elif type(_xin, `=`) and lhs(_xin) = "eventfired" then if not type(rhs(_xin), 'list') then error "'eventfired' must be specified as a list" end if; if _nv = 0 then error "this solution has no events" end if; if _dtbl[4] <> 2 and _dtbl[4] <> 3 then error "'direction' must be set prior to calling/setting 'eventfired'" end if; _i := _dtbl[4]; _val := NULL; if not assigned(_EnvEventRetriggerWarned) then _EnvEventRetriggerWarned := false end if; for _k in rhs(_xin) do if type(_k, 'integer') then _src := _k elif type(_k, 'integer' = 'anything') and type(evalf(rhs(_k)), 'numeric') then _k := lhs(_k) = evalf[max(Digits, 18)](rhs(_k)); _src := lhs(_k) else error "'eventfired' entry is not valid: %1", _k end if; if _src < 1 or round(_dtbl[1][3][1][_nv+1, 1]) < _src then error "event identifiers must be integers in the range 1..%1", round(_dtbl[1][3][1][_nv+1, 1]) end if; _src := {seq(`if`(_dtbl[1][3][1][_j, 1]-_src = 0., _j, NULL), _j = 1 .. _nv)}; if nops(_src) <> 1 then error "'eventfired' can only be set/queried for root-finding events and time/interval events" end if; _src := _src[1]; if _dtbl[1][3][1][_src, 2] <> 0. and _dtbl[1][3][1][_src, 2]-2. <> 0. then error "'eventfired' can only be set/queried for root-finding events and time/interval events" elif irem(round(_dtbl[1][3][1][_src, 4]), 2) = 1 then if _EnvEventRetriggerWarned = false then WARNING(`'eventfired' has no effect on events that retrigger`) end if; _EnvEventRetriggerWarned := true end if; if _dtbl[_i][3][1][_src, 2] = 0 and irem(iquo(round(_dtbl[_i][3][1][_src, 4]), 32), 2) = 1 then _val := _val, undefined elif type(_dtbl[_i][3][4][_src, _i-1], 'undefined') or _i = 2 and _dtbl[2][3][1][_src, 8] < _dtbl[2][3][4][_src, 1] or _i = 3 and _dtbl[3][3][4][_src, 2] < _dtbl[3][3][1][_src, 8] then _val := _val, _dtbl[_i][3][1][_src, 8] else _val := _val, _dtbl[_i][3][4][_src, _i-1] end if; if type(_k, `=`) then if _dtbl[_i][3][1][_src, 2] = 0 and irem(iquo(round(_dtbl[_i][3][1][_src, 4]), 32), 2) = 1 then error "cannot set event code for a rate hysteresis event" end if; userinfo(3, {'events', 'eventreset'}, `manual set event code `, _src, ` to value `, rhs(_k)); _dtbl[_i][3][1][_src, 8] := rhs(_k); _dtbl[_i][3][4][_src, _i-1] := rhs(_k) end if end do; return [_val] elif type(_xin, `=`) and lhs(_xin) = "direction" then if not member(rhs(_xin), {-1, 1, ':-left', ':-right'}) then error "'direction' must be specified as either '1' or 'right' (positive) or '-1' or 'left' (negative)" end if; _src := `if`(_dtbl[4] = 2, -1, `if`(_dtbl[4] = 3, 1, undefined)); _i := `if`(member(rhs(_xin), {1, ':-right'}), 3, 2); _dtbl[4] := _i; _dtbl[_i] := `dsolve/numeric/SC/IVPdcopy`(_dtbl[1], `if`(assigned(_dtbl[_i]), _dtbl[_i], NULL)); if 0 < _nv then for _j to _nv+1 do if _j <= _nv and not type(_dtbl[_i][3][4][_j, _i-1], 'undefined') then userinfo(3, {'events', 'eventreset'}, `reinit #4, event code `, _j, ` to defined init `, _dtbl[_i][3][4][_j, _i-1]); _dtbl[_i][3][1][_j, 8] := _dtbl[_i][3][4][_j, _i-1] elif _dtbl[_i][3][1][_j, 2] = 0 and irem(iquo(round(_dtbl[_i][3][1][_j, 4]), 32), 2) = 1 then userinfo(3, {'events', 'eventreset'}, `reinit #4, event code `, _j, ` to rate hysteresis init `, _dtbl[_i][5][24]); _dtbl[_i][3][1][_j, 8] := _dtbl[_i][5][24] elif _dtbl[_i][3][1][_j, 2] = 0 and irem(iquo(round(_dtbl[_i][3][1][_j, 4]), 2), 2) = 0 then userinfo(3, {'events', 'eventreset'}, `reinit #4, event code `, _j, ` to initial init `, _x0); _dtbl[_i][3][1][_j, 8] := _x0 else userinfo(3, {'events', 'eventreset'}, `reinit #4, event code `, _j, ` to fireinitial init `, _x0-2*_i+5.0); _dtbl[_i][3][1][_j, 8] := _x0-2*_i+5.0 end if end do end if; return _src elif _xin = "eventcount" then if _dtbl[1][3][1] = 0 or _dtbl[4] <> 2 and _dtbl[4] <> 3 then return 0 else return round(_dtbl[_dtbl[4]][3][1][_nv+1, 12]) end if else return "procname" end if end if; if _xout = _x0 then return [_x0, seq(evalf(_dtbl[1][6][_vmap[_i]]), _i = 1 .. _n-_ne)] end if; _i := `if`(_x0 <= _xout, 3, 2); if _xin = "last" and 0 < _dtbl[_i][4][9] and _dtbl[_i][4][9] < 100 then _dat := eval(_dtbl[_i], 2); _j := _dat[4][20]; return [_dat[11][_j, 0], seq(_dat[11][_j, _vmap[_i]], _i = 1 .. _n-_ne-_nd), seq(_dat[8][1][_vmap[_i]], _i = _n-_ne-_nd+1 .. _n-_ne)] end if; if not type(_dtbl[_i], 'array') then _dtbl[_i] := `dsolve/numeric/SC/IVPdcopy`(_dtbl[1], `if`(assigned(_dtbl[_i]), _dtbl[_i], NULL)); if 0 < _nv then for _j to _nv+1 do if _j <= _nv and not type(_dtbl[_i][3][4][_j, _i-1], 'undefined') then userinfo(3, {'events', 'eventreset'}, `reinit #5, event code `, _j, ` to defined init `, _dtbl[_i][3][4][_j, _i-1]); _dtbl[_i][3][1][_j, 8] := _dtbl[_i][3][4][_j, _i-1] elif _dtbl[_i][3][1][_j, 2] = 0 and irem(iquo(round(_dtbl[_i][3][1][_j, 4]), 32), 2) = 1 then userinfo(3, {'events', 'eventreset'}, `reinit #5, event code `, _j, ` to rate hysteresis init `, _dtbl[_i][5][24]); _dtbl[_i][3][1][_j, 8] := _dtbl[_i][5][24] elif _dtbl[_i][3][1][_j, 2] = 0 and irem(iquo(round(_dtbl[_i][3][1][_j, 4]), 2), 2) = 0 then userinfo(3, {'events', 'eventreset'}, `reinit #5, event code `, _j, ` to initial init `, _x0); _dtbl[_i][3][1][_j, 8] := _x0 else userinfo(3, {'events', 'eventreset'}, `reinit #5, event code `, _j, ` to fireinitial init `, _x0-2*_i+5.0); _dtbl[_i][3][1][_j, 8] := _x0-2*_i+5.0 end if end do end if end if; if _xin <> "last" then if 0 < 0 then if `dsolve/numeric/checkglobals`(op(_dtbl[1][14]), _pars, _n, _y0) then `dsolve/numeric/SC/reinitialize`(_dtbl, _y0, _n, procname, _pars, _i) end if end if; if _dtbl[1][4][7] = 0 then error "parameters must be initialized before solution can be computed" end if end if; _dat := eval(_dtbl[_i], 2); _dtbl[4] := _i; try _src := `dsolve/numeric/SC/IVPrun`(_dat, _xout) catch: userinfo(2, `dsolve/debug`, print(`Exception in solnproc:`, [lastexception][2 .. -1])); error  end try; if _dat[17] <> _dtbl[1][17] then _dtbl[1][17] := _dat[17]; _dtbl[1][10] := _dat[10] end if; if _src = 0 and 100 < _dat[4][9] then _val := _dat[3][1][_nv+1, 8] else _val := _dat[11][_dat[4][20], 0] end if; if _src <> 0 or _dat[4][9] <= 0 then _dtbl[1][5][1] := _xout else _dtbl[1][5][1] := _val end if; if _i = 3 and _val < _xout then Rounding := -infinity; if _dat[4][9] = 1 then error "cannot evaluate the solution further right of %1, probably a singularity", evalf[8](_val) elif _dat[4][9] = 2 then error "cannot evaluate the solution further right of %1, maxfun limit exceeded (see ?dsolve,maxfun for details)", evalf[8](_val) elif _dat[4][9] = 3 then if _dat[4][25] = 3 then error "cannot evaluate the solution past the initial point, problem may be initially singular or improperly set up" else error "cannot evaluate the solution past the initial point, problem may be complex, initially singular or improperly set up" end if elif _dat[4][9] = 4 then error "cannot evaluate the solution further right of %1, accuracy goal cannot be achieved with specified 'minstep'", evalf[8](_val) elif _dat[4][9] = 5 then error "cannot evaluate the solution further right of %1, too many step failures, tolerances may be too loose for problem", evalf[8](_val) elif _dat[4][9] = 6 then error "cannot evaluate the solution further right of %1, cannot downgrade delay storage for problems with delay derivative order > 1, try increasing delaypts", evalf[8](_val) elif _dat[4][9] = 10 then error "cannot evaluate the solution further right of %1, interrupt requested", evalf[8](_val) elif 100 < _dat[4][9] then if _dat[4][9]-100 = _nv+1 then error "constraint projection failure on event at t=%1", evalf[8](_val) elif _dat[4][9]-100 = _nv+2 then error "index-1 and derivative evaluation failure on event at t=%1", evalf[8](_val) elif _dat[4][9]-100 = _nv+3 then error "maximum number of event iterations reached (%1) at t=%2", round(_dat[3][1][_nv+1, 3]), evalf[8](_val) else if _Env_dsolve_nowarnstop <> true then `dsolve/numeric/warning`(StringTools:-FormatMessage("cannot evaluate the solution further right of %1, event #%2 triggered a halt", evalf[8](_val), round(_dat[3][1][_dat[4][9]-100, 1]))) end if; Rounding := 'nearest'; _xout := _val end if else error "cannot evaluate the solution further right of %1", evalf[8](_val) end if elif _i = 2 and _xout < _val then Rounding := infinity; if _dat[4][9] = 1 then error "cannot evaluate the solution further left of %1, probably a singularity", evalf[8](_val) elif _dat[4][9] = 2 then error "cannot evaluate the solution further left of %1, maxfun limit exceeded (see ?dsolve,maxfun for details)", evalf[8](_val) elif _dat[4][9] = 3 then if _dat[4][25] = 3 then error "cannot evaluate the solution past the initial point, problem may be initially singular or improperly set up" else error "cannot evaluate the solution past the initial point, problem may be complex, initially singular or improperly set up" end if elif _dat[4][9] = 4 then error "cannot evaluate the solution further left of %1, accuracy goal cannot be achieved with specified 'minstep'", evalf[8](_val) elif _dat[4][9] = 5 then error "cannot evaluate the solution further left of %1, too many step failures, tolerances may be too loose for problem", evalf[8](_val) elif _dat[4][9] = 6 then error "cannot evaluate the solution further left of %1, cannot downgrade delay storage for problems with delay derivative order > 1, try increasing delaypts", evalf[8](_val) elif _dat[4][9] = 10 then error "cannot evaluate the solution further right of %1, interrupt requested", evalf[8](_val) elif 100 < _dat[4][9] then if _dat[4][9]-100 = _nv+1 then error "constraint projection failure on event at t=%1", evalf[8](_val) elif _dat[4][9]-100 = _nv+2 then error "index-1 and derivative evaluation failure on event at t=%1", evalf[8](_val) elif _dat[4][9]-100 = _nv+3 then error "maximum number of event iterations reached (%1) at t=%2", round(_dat[3][1][_nv+1, 3]), evalf[8](_val) else if _Env_dsolve_nowarnstop <> true then `dsolve/numeric/warning`(StringTools:-FormatMessage("cannot evaluate the solution further left of %1, event #%2 triggered a halt", evalf[8](_val), round(_dat[3][1][_dat[4][9]-100, 1]))) end if; Rounding := 'nearest'; _xout := _val end if else error "cannot evaluate the solution further left of %1", evalf[8](_val) end if end if; if _EnvInFsolve = true then _dig := _dat[4][26]; _dat[4][26] := _EnvDSNumericSaveDigits; _Env_dsolve_SC_native := true; if _dat[4][25] = 1 then _i := 1; _dat[4][25] := 2 else _i := _dat[4][25] end if; _val := `dsolve/numeric/SC/IVPval`(_dat, _xout, _src); _dat[4][25] := _i; _dat[4][26] := _dig; [_xout, seq(_val[_vmap[_i]], _i = 1 .. _n-_ne)] else Digits := _dat[4][26]; _val := `dsolve/numeric/SC/IVPval`(eval(_dat, 2), _xout, _src); [_xout, seq(_val[_vmap[_i]], _i = 1 .. _n-_ne)] end if end proc, (2) = Array(0..0, {}), (3) = [t, x(t), diff(x(t), t)], (4) = []}); _vars := _dat[3]; _pars := map(rhs, _dat[4]); _n := nops(_vars)-1; _solnproc := _dat[1]; if not type(_xout, 'numeric') then if member(x_rkf45, ["start", 'start', "method", 'method', "left", 'left', "right", 'right', "leftdata", "rightdata", "enginedata", "eventstop", 'eventstop', "eventclear", 'eventclear', "eventstatus", 'eventstatus', "eventcount", 'eventcount', "laxtol", 'laxtol', "numfun", 'numfun', NULL]) then _res := _solnproc(convert(x_rkf45, 'string')); if 1 < nops([_res]) then return _res elif type(_res, 'array') then return eval(_res, 1) elif _res <> "procname" then return _res end if elif member(x_rkf45, ["last", 'last', "initial", 'initial', "parameters", 'parameters', "initial_and_parameters", 'initial_and_parameters', NULL]) then _xout := convert(x_rkf45, 'string'); _res := _solnproc(_xout); if _xout = "parameters" then return [seq(_pars[_i] = _res[_i], _i = 1 .. nops(_pars))] elif _xout = "initial_and_parameters" then return [seq(_vars[_i+1] = [_res][1][_i+1], _i = 0 .. _n), seq(_pars[_i] = [_res][2][_i], _i = 1 .. nops(_pars))] else return [seq(_vars[_i+1] = _res[_i+1], _i = 0 .. _n)] end if elif type(_xout, `=`) and member(lhs(_xout), ["initial", 'initial', "parameters", 'parameters', "initial_and_parameters", 'initial_and_parameters', NULL]) then _xout := convert(lhs(x_rkf45), 'string') = rhs(x_rkf45); if type(rhs(_xout), 'list') then _res := _solnproc(_xout) else error "initial and/or parameter values must be specified in a list" end if; if lhs(_xout) = "initial" then return [seq(_vars[_i+1] = _res[_i+1], _i = 0 .. _n)] elif lhs(_xout) = "parameters" then return [seq(_pars[_i] = _res[_i], _i = 1 .. nops(_pars))] else return [seq(_vars[_i+1] = [_res][1][_i+1], _i = 0 .. _n), seq(_pars[_i] = [_res][2][_i], _i = 1 .. nops(_pars))] end if elif type(_xout, `=`) and member(lhs(_xout), ["eventdisable", 'eventdisable', "eventenable", 'eventenable', "eventfired", 'eventfired', "direction", 'direction', NULL]) then return _solnproc(convert(lhs(x_rkf45), 'string') = rhs(x_rkf45)) elif _xout = "solnprocedure" then return eval(_solnproc) elif _xout = "sysvars" then return _vars end if; if procname <> unknown then return ('procname')(x_rkf45) else _ndsol := 1; _ndsol := _ndsol; _ndsol := pointto(_dat[2][0]); return ('_ndsol')(x_rkf45) end if end if; try _res := _solnproc(_xout); [seq(_vars[_i+1] = _res[_i+1], _i = 0 .. _n)] catch: error  end try end proc

(3)

nsol(1);

[t = 1., x(t) = HFloat(5.571898660410449), diff(x(t), t) = HFloat(5.165893624858025)]

(4)

eval(x(t), nsol(1));

HFloat(5.571898660410449)

(5)

odeplot( nsol, [[t,x(t)],[t,diff(x(t),t)]], 0..1, legend=[`x(t)`,`x'(t)`], title="Figure 1.1" );

 

odeplot( nsol, [t,x(t)-diff(x(t),t)], 0..10, title="Figure 1.2" );

 

Xeuler := dsolve( {ode2,ic3}, x(t), type=numeric, method=classical, stepsize=0.1 );

proc (x_classical) local _res, _dat, _vars, _solnproc, _xout, _ndsol, _pars, _n, _i; option `Copyright (c) 2000 by Waterloo Maple Inc. All rights reserved.`; if 1 < nargs then error "invalid input: too many arguments" end if; _EnvDSNumericSaveDigits := Digits; Digits := 15; if _EnvInFsolve = true then _xout := evalf[_EnvDSNumericSaveDigits](x_classical) else _xout := evalf(x_classical) end if; _dat := Array(1..4, {(1) = proc (_xin) local _xout, _n, _y0, _yn, _yl, _ctl, _octl, _reinit, _errcd, _fcn, _i, _yini, _pars, _ini, _par; option `Copyright (c) 2002 by the University of Waterloo. All rights reserved.`; table( [( "complex" ) = false ] ) _xout := _xin; _ctl := Array(1..9, {(1) = 2, (2) = 0., (3) = 0., (4) = .1, (5) = 50000, (6) = 0, (7) = 0, (8) = 1, (9) = 0}); _octl := Array(1..9, {(1) = 2, (2) = 0., (3) = 0., (4) = .1, (5) = 50000, (6) = 0, (7) = 0, (8) = 1, (9) = 0}); _n := trunc(_ctl[1]); _yini := Array(0..2, {(1) = 0., (2) = 3.}); _y0 := Array(0..2, {(1) = 0., (2) = 3.}); _yl := Array(1..2, {(1) = 0, (2) = 0}); _yn := Array(1..2, {(1) = 0, (2) = 0}); _fcn := proc (N, X, Y, YP) option `[Y[1] = x(t), Y[2] = diff(x(t),t)]`; YP[2] := -Y[2]+2*Y[1]; YP[1] := Y[2]; 0 end proc; _pars := []; if not type(_xout, 'numeric') then if member(_xout, ["start", "left", "right"]) then return _y0[0] elif _xout = "method" then return "classical" elif _xout = "numfun" then return round(_ctl[6]) elif _xout = "initial" then return [seq(_yini[_i], _i = 0 .. _n)] elif _xout = "parameters" then return [seq(_yini[_n+_i], _i = 1 .. nops(_pars))] elif _xout = "initial_and_parameters" then return [seq(_yini[_i], _i = 0 .. _n)], [seq(_yini[_n+_i], _i = 1 .. nops(_pars))] elif _xout = "last" then if _ctl[3]-_y0[0] <> 0. then _xout := _ctl[3] elif _ctl[2]-_y0[0] <> 0. then _xout := _ctl[2] else error "no information is available on last computed point" end if elif _xout = "enginedata" then return eval(_octl, 1) elif _xout = "function" then return eval(_fcn, 1) elif type(_xin, `=`) and type(rhs(_xin), 'list') and member(lhs(_xin), {"initial", "parameters", "initial_and_parameters"}) then _ini, _par := [], []; if lhs(_xin) = "initial" then _ini := rhs(_xin) elif lhs(_xin) = "parameters" then _par := rhs(_xin) elif select(type, rhs(_xin), `=`) <> [] then _par, _ini := selectremove(type, rhs(_xin), `=`) elif nops(rhs(_xin)) < nops(_pars)+1 then error "insufficient data for specification of initial and parameters" else _par := rhs(_xin)[-nops(_pars) .. -1]; _ini := rhs(_xin)[1 .. -nops(_pars)-1] end if; _xout := lhs(_xout); if _par <> [] then `dsolve/numeric/process_parameters`(_n, _pars, _par, _yini) end if; if _ini <> [] then `dsolve/numeric/process_initial`(_n, _ini, _yini, _pars) end if; if _pars <> [] then _par := {seq(rhs(_pars[_i]) = _yini[_n+_i], _i = 1 .. nops(_pars))}; for _i from 0 to _n do _y0[_i] := subs(_par, _yini[_i]) end do; for _i from _n+1 to _n+nops(_pars) do _y0[_i] := _yini[_i] end do; for _i to nops(_pars) do _yn[_n+_i] := _y0[_n+_i] end do else for _i from 0 to _n do _y0[_i] := _yini[_i] end do end if; _octl[2] := _y0[0]; _octl[3] := _y0[0]; for _i to 9 do _ctl[_i] := _octl[_i] end do; for _i to _n+nops(_pars) do _yl[_i] := _y0[_i] end do; if _Env_smart_dsolve_numeric = true and type(_y0[0], 'numeric') then procname("right") := _y0[0]; procname("left") := _y0[0] end if; if _xout = "initial" then return [seq(_yini[_i], _i = 0 .. _n)] elif _xout = "parameters" then return [seq(_yini[_n+_i], _i = 1 .. nops(_pars))] else return [seq(_yini[_i], _i = 0 .. _n), op(_pars)], [seq(_yini[_n+_i], _i = 1 .. nops(_pars))] end if else return "procname" end if end if; if _xout-_y0[0] = 0. then return [seq(_y0[_i], _i = 0 .. _n)] end if; _reinit := false; if _xin <> "last" then if 0 < 0 and `dsolve/numeric/checkglobals`(0, table( [ ] ), _pars, _n, _yini) then _reinit := true; if _pars <> [] then _par := {seq(rhs(_pars[_i]) = _yini[_n+_i], _i = 1 .. nops(_pars))}; for _i from 0 to _n do _y0[_i] := subs(_par, _yini[_i]) end do; for _i from _n+1 to _n+nops(_pars) do _y0[_i] := _yini[_i] end do; for _i to nops(_pars) do _yn[_n+_i] := _y0[_n+_i] end do else for _i from 0 to _n do _y0[_i] := _yini[_i] end do end if end if; if _pars <> [] and select(type, {seq(_yini[_n+_i], _i = 1 .. nops(_pars))}, 'undefined') <> {} then error "parameters must be initialized before solution can be computed" end if end if; if not _reinit and _xout-_ctl[3] = 0. then [_ctl[3], seq(_yn[_i], _i = 1 .. _n)] elif not _reinit and _xout-_ctl[2] = 0. then [_ctl[2], seq(_yl[_i], _i = 1 .. _n)] else if _ctl[2]-_y0[0] = 0. or sign(_ctl[2]-_y0[0]) <> sign(_xout-_ctl[2]) or abs(_xout-_y0[0]) < abs(_xout-_ctl[2]) or _reinit then for _i to 9 do _ctl[_i] := _octl[_i] end do; for _i to _n+nops(_pars) do _yl[_i] := _y0[_i] end do; for _i to nops(_pars) do _yn[_n+_i] := _y0[_n+_i] end do end if; _ctl[3] := _xout; if Digits <= evalhf(Digits) then try _errcd := evalhf(`dsolve/numeric/classical`(_fcn, var(_ctl), _y0[0], var(_yl), var(_yn), Array(1..2, {(1) = 0, (2) = 0}), Array(1..2, {(1) = 0, (2) = 0}), Array(1..2, {(1) = 0, (2) = 0}), Array(1..2, {(1) = 0, (2) = 0}), var(Array(1..3, 1..2, {(1, 1) = 0, (1, 2) = 0, (2, 1) = 0, (2, 2) = 0, (3, 1) = 0, (3, 2) = 0})))) catch: userinfo(2, `dsolve/debug`, print(`Exception in classical:`, [lastexception])); if searchtext('evalhf', lastexception[2]) <> 0 or searchtext('real', lastexception[2]) <> 0 or searchtext('hardware', lastexception[2]) <> 0 then _errcd := `dsolve/numeric/classical`(_fcn, _ctl, _y0[0], _yl, _yn, Array(1..2, {(1) = 0, (2) = 0}), Array(1..2, {(1) = 0, (2) = 0}), Array(1..2, {(1) = 0, (2) = 0}), Array(1..2, {(1) = 0, (2) = 0}), Array(1..3, 1..2, {(1, 1) = 0, (1, 2) = 0, (2, 1) = 0, (2, 2) = 0, (3, 1) = 0, (3, 2) = 0})) else _ctl[3] := _y0[0]; _errcd := [lastexception][2 .. -1] end if end try else try _errcd := `dsolve/numeric/classical`(_fcn, _ctl, _y0[0], _yl, _yn, Array(1..2, {(1) = 0, (2) = 0}), Array(1..2, {(1) = 0, (2) = 0}), Array(1..2, {(1) = 0, (2) = 0}), Array(1..2, {(1) = 0, (2) = 0}), Array(1..3, 1..2, {(1, 1) = 0, (1, 2) = 0, (2, 1) = 0, (2, 2) = 0, (3, 1) = 0, (3, 2) = 0})) catch: _ctl[3] := _y0[0]; _errcd := [lastexception][2 .. -1] end try end if; if type(_errcd, 'list') or _errcd < 0 then userinfo(2, {dsolve, `dsolve/classical`}, `Last values returned:`); userinfo(2, {dsolve, `dsolve/classical`}, ` t =`, _ctl[2]); userinfo(2, {dsolve, `dsolve/classical`}, ` y =`, _yl[1]); for _i from 2 to _n do userinfo(2, {dsolve, `dsolve/classical`}, `	 `, _yl[_i]) end do; if type(_errcd, 'list') then error op(_errcd) elif _errcd+1. = 0. then Rounding := `if`(_y0[0] < _xout, -infinity, infinity); error "cannot evaluate the solution past %1, maxfun limit exceeded (see ?dsolve,maxfun for details)", evalf[8](_ctl[3]) else Rounding := `if`(_y0[0] < _xout, -infinity, infinity); error "cannot evaluate the solution past %1, unknown error code returned from classical %2", evalf[8](_ctl[3]), trunc(_errcd) end if end if; if _Env_smart_dsolve_numeric = true then if _y0[0] < _xout and procname("right") < _xout then procname("right") := _xout elif _xout < _y0[0] and _xout < procname("left") then procname("left") := _xout end if end if; [_xout, seq(_yn[_i], _i = 1 .. _n)] end if end proc, (2) = Array(0..0, {}), (3) = [t, x(t), diff(x(t), t)], (4) = []}); _vars := _dat[3]; _pars := map(rhs, _dat[4]); _n := nops(_vars)-1; _solnproc := _dat[1]; if not type(_xout, 'numeric') then if member(x_classical, ["start", 'start', "method", 'method', "left", 'left', "right", 'right', "leftdata", "rightdata", "enginedata", "eventstop", 'eventstop', "eventclear", 'eventclear', "eventstatus", 'eventstatus', "eventcount", 'eventcount', "laxtol", 'laxtol', "numfun", 'numfun', NULL]) then _res := _solnproc(convert(x_classical, 'string')); if 1 < nops([_res]) then return _res elif type(_res, 'array') then return eval(_res, 1) elif _res <> "procname" then return _res end if elif member(x_classical, ["last", 'last', "initial", 'initial', "parameters", 'parameters', "initial_and_parameters", 'initial_and_parameters', NULL]) then _xout := convert(x_classical, 'string'); _res := _solnproc(_xout); if _xout = "parameters" then return [seq(_pars[_i] = _res[_i], _i = 1 .. nops(_pars))] elif _xout = "initial_and_parameters" then return [seq(_vars[_i+1] = [_res][1][_i+1], _i = 0 .. _n), seq(_pars[_i] = [_res][2][_i], _i = 1 .. nops(_pars))] else return [seq(_vars[_i+1] = _res[_i+1], _i = 0 .. _n)] end if elif type(_xout, `=`) and member(lhs(_xout), ["initial", 'initial', "parameters", 'parameters', "initial_and_parameters", 'initial_and_parameters', NULL]) then _xout := convert(lhs(x_classical), 'string') = rhs(x_classical); if type(rhs(_xout), 'list') then _res := _solnproc(_xout) else error "initial and/or parameter values must be specified in a list" end if; if lhs(_xout) = "initial" then return [seq(_vars[_i+1] = _res[_i+1], _i = 0 .. _n)] elif lhs(_xout) = "parameters" then return [seq(_pars[_i] = _res[_i], _i = 1 .. nops(_pars))] else return [seq(_vars[_i+1] = [_res][1][_i+1], _i = 0 .. _n), seq(_pars[_i] = [_res][2][_i], _i = 1 .. nops(_pars))] end if elif type(_xout, `=`) and member(lhs(_xout), ["eventdisable", 'eventdisable', "eventenable", 'eventenable', "eventfired", 'eventfired', "direction", 'direction', NULL]) then return _solnproc(convert(lhs(x_classical), 'string') = rhs(x_classical)) elif _xout = "solnprocedure" then return eval(_solnproc) elif _xout = "sysvars" then return _vars end if; if procname <> unknown then return ('procname')(x_classical) else _ndsol := 1; _ndsol := _ndsol; _ndsol := pointto(_dat[2][0]); return ('_ndsol')(x_classical) end if end if; try _res := _solnproc(_xout); [seq(_vars[_i+1] = _res[_i+1], _i = 0 .. _n)] catch: error  end try end proc

(6)

        p1 := odeplot( nsol, [t,x(t)], 0..2, color=red ):

        p2 := odeplot( Xeuler, [t,x(t)], 0..2, color=blue ):

display( [p1,p2], title="Figure 1.3" );

 

times := Array( [i/10$i=0..10, $2..10] );

Vector[row](20, {(1) = 0, (2) = 0, (3) = 0, (4) = 0, (5) = 0, (6) = 0, (7) = 0, (8) = 0, (9) = 0, (10) = 0, (11) = 0, (12) = 0, (13) = 0, (14) = 0, (15) = 0, (16) = 0, (17) = 0, (18) = 0, (19) = 0, (20) = 0})

(7)

t1 := dsolve( {ode2,ic3}, x(t), type=numeric, method=classical[foreuler], output=Array([i/10$i=0..10, $2..10]) );

Vector(2, {(1) = Vector[row](3, {(1) = t, (2) = t, (3) = t}), (2) = Matrix(20, 3, {(1, 1) = 0., (1, 2) = 3., (1, 3) = 0., (2, 1) = .100000000000000, (2, 2) = 3.027698091970692, (2, 3) = .5739772791789997, (3, 1) = .200000000000000, (3, 2) = 3.1105602315432774, (3, 3) = 1.103644955834236, (4, 1) = .300000000000000, (4, 2) = 3.244856947489392, (4, 3) = 1.6033870203171081, (5, 1) = .400000000000000, (5, 2) = 3.428200349442581, (5, 3) = 2.085630708151149, (6, 1) = .500000000000000, (6, 2) = 3.659369325506314, (6, 3) = 2.561272301686627, (7, 1) = .600000000000000, (7, 2) = 3.938173859376953, (7, 3) = 3.0400326854399595, (8, 1) = .700000000000000, (8, 2) = 4.265352108195497, (8, 3) = 3.530756211090707, (9, 1) = .800000000000000, (9, 2) = 4.642495120436593, (9, 3) = 4.041664039864123, (10, 1) = .900000000000000, (10, 2) = 5.071995094202509, (10, 3) = 4.580571185078244, (11, 1) = 1., (11, 2) = 5.557013920716705, (11, 3) = 5.155074896142818, (12, 1) = 2., (12, 2) = 14.722600769153727, (12, 3) = 14.668749109328592, (13, 1) = 3., (13, 2) = 39.87431585633435, (13, 3) = 39.86710082846041, (14, 1) = 4., (14, 2) = 108.11369120803583, (14, 3) = 108.1127245409472, (15, 1) = 5., (15, 2) = 293.1512943934876, (15, 3) = 293.1511648797455, (16, 1) = 6., (16, 2) = 794.8846430813624, (16, 3) = 794.8846257291527, (17, 1) = 7., (17, 2) = 2155.3433055601067, (17, 3) = 2155.343303235263, (18, 1) = 8., (18, 2) = 5844.2502768200975, (18, 3) = 5844.250276508616, (19, 1) = 9., (19, 2) = 15846.784696012406, (19, 3) = 15846.78469597067, (20, 1) = 10., (20, 2) = 42968.828046570256, (20, 3) = 42968.82804656467})})

(8)

        t1[2,1][6,2];

HFloat(3.659369325506314)

(9)

t2 := dsolve( {ode2,ic3}, x(t), type=numeric, method=classical[abmoulton], output=Array([i/10$i=0..10, $2..10]) ):

        header1 := <` t `| `Forward Euler`| `Predictor-Corrector`>:

header2 := <`---`| `-------------`| `-------------------`>:

< header1, header2, <Column(t1[2,1],1..2) | Column(t2[2,1],2) > >;

Matrix(22, 3, {(1, 1) = ` t `, (1, 2) = `Forward Euler`, (1, 3) = `Predictor-Corrector`, (2, 1) = `---`, (2, 2) = `-------------`, (2, 3) = `-------------------`, (3, 1) = 0., (3, 2) = 3., (3, 3) = 3., (4, 1) = .100000000000000, (4, 2) = 3.027698091970692, (4, 3) = 3.0290725891979045, (5, 1) = .200000000000000, (5, 2) = 3.1105602315432774, (5, 3) = 3.113125562297365, (6, 1) = .300000000000000, (6, 2) = 3.244856947489392, (6, 3) = 3.2485292511735357, (7, 1) = .400000000000000, (7, 2) = 3.428200349442581, (7, 3) = 3.43297835932337, (8, 1) = .500000000000000, (8, 2) = 3.659369325506314, (8, 3) = 3.665321982498908, (9, 1) = .600000000000000, (9, 2) = 3.938173859376953, (9, 3) = 3.945431812629719, (10, 1) = .700000000000000, (10, 2) = 4.265352108195497, (10, 3) = 4.27410237883276, (11, 1) = .800000000000000, (11, 2) = 4.642495120436593, (11, 3) = 4.652978374947043, (12, 1) = .900000000000000, (12, 2) = 5.071995094202509, (12, 3) = 5.08450511052321, (13, 1) = 1., (13, 2) = 5.557013920716705, (13, 3) = 5.571898940165442, (14, 1) = 2., (14, 2) = 14.722600769153727, (14, 3) = 14.796427837196497, (15, 1) = 3., (15, 2) = 39.87431585633435, (15, 3) = 40.17355260045988, (16, 1) = 4., (16, 2) = 108.11369120803583, (16, 3) = 109.19663553586172, (17, 1) = 5., (17, 2) = 293.1512943934876, (17, 3) = 296.8263636287175, (18, 1) = 6., (18, 2) = 794.8846430813624, (18, 3) = 806.857593206849, (19, 1) = 7., (19, 2) = 2155.3433055601067, (19, 3) = 2193.266317933328, (20, 1) = 8., (20, 2) = 5844.2502768200975, (20, 3) = 5961.91597495713, (21, 1) = 9., (21, 2) = 15846.784696012406, (21, 3) = 16206.167857491657, (22, 1) = 10., (22, 2) = 42968.828046570256, (22, 3) = 44052.93159663493})

(10)

 

Download opSize.mw

 

both of your examples. Not sure which one you actually want!?

 restart;
  sol1:=rsolve({U(n)=3*(U(n-3)+U(n-4))+6, U(0) = 6, U(1) = 6, U(2) = 6, U(3)=24}, {U}, 'makeproc'):
  seq( sol1(j), j=0..10);
  sol2:=rsolve({U(n)=U(n-1)+4*U(n-3) ,U(0) = 6,U(1) = 12,U(2) = 18, U(3)=42}, {U}, 'makeproc'):
  seq( sol2(j), j=0..10);

 

precisely what you want, but maybe(?) something like

L:=[seq((L||j)(a_1, a_2,a_3), j=1..4)];
R:=[seq((R||j)(a_1, a_2,a_3), j=1..4)];
M:=Matrix(4,4, (i,j)->L[i]=R[j]);
M[2,3]:=eval( M[2,3], [a_1=1,a_2=3,a_3=4]):
M;

 

my previous responses.

Although I note that you have (somehow?) deleted your original questions/worksheets. This just makes the current question almost impossible for any other responder to understand. Don't do this!

The attached will return the maximum entry in each column of the output table - although as I said in a previus response

stores the result in a table (which isn't necessarily the most convenient data structure for subsequent processing!)


 

  restart;
  with(Optimization):
  G:=a-b*p:
  z:=q-G:
  M:=int((z-u)*f(u), u=-3500..z):
  N:=int((u-z)*f(u), u=z..1500):
  beta:=alpha*K+(1-K)*r/p:
  E__pi:=(p-c)*(G+mu)-(c-v)*M-(p-c+s-beta*(p-r-c-d+s))*N:
  EXE__pi := eval( E__pi,
                   [ c = 35,
                     a = 100000,
                     b = 1500,
                     mu = -1000,
                     v = 10,
                     d = 3,
                     s = 3,
                     f(u)= exp((-1/800)*(u+1000)*(u+1000))/sqrt(2*3.14*800)
                   ]
                 ):
  DEP__pi:=diff(EXE__pi, p):
  DEQ__pi:=diff(EXE__pi, q):
  DER__pi:=diff(EXE__pi, r):
#
# Suppress printing of NLPSolve() output
#
# printf( "%2s %14s %13s %13s %13s\n\n",
#         "k", "maximum", "p", "q", "r"
#       );
#
# Set up output table
#
  myName:=table():
  for k from 0.1 by 0.02 to 0.40 do
      E1__pi:=eval(EXE__pi,[alpha = 0.5, K=k]):
      #printf("%a   ", k);
      try  ans:= NLPSolve
                 ( E1__pi,
                   p = 40 .. 60,
                   q = 15000 .. 26000,
                   r = 0 .. 25,
                   initialpoint = {p = 50, q = 15000, r = 0},
                   maximize
                 ):
        #
        # Suppress printing of NLPSolve output
        #
        # printf( "%4.2f   %8.6e   %8.6e   %8.6e   %8.6e \n",
        #         k, ans[1], rhs~(ans[2])[]
        #      );
        #
        # Use outputs of NLPSolve to compute a
        # few things and store these in the
        # table myName, indexed by the value of
        # the loop variable k
        #
          myName[k] := eval( [ DEP__pi,
                               DEQ__pi,
                               DER__pi,
                               beta
                            ],
                            [ alpha = .5,
                              K = k,
                              ans[2][]
                            ]
                          ):
    catch "Error, (in Optimization:-NLPSolve) no improved point could be found":
        #
        # Print warning message when NLPSolve()
        # command fails
        #
          printf("\n**NLPSolve() failed when k=%4.2f**\n\n", k);
    end try:
    
  od:
#
# Check output table contents for a couple
# of index values
#
  myName[0.1];
  myName[0.28];
#
# Print the complete contents of the output
# table
#
  printf( "\n\n%2s%16s%17s%17s%17s\n\n",
          "k", 'DEP__pi', 'DEQ__pi', 'DER__pi', 'beta'
        );
  seq
  ( printf( "%4.2f%17.6e%17.6e%17.6e%17.6e \n",
            j, myName[j][]
          ),
    j in  sort( [ indices(myName, 'nolist' ) ] )
  );


**NLPSolve() failed when k=0.20**


**NLPSolve() failed when k=0.36**

 

[HFloat(0.008124235024297377), HFloat(1.3244345424823223e-6), HFloat(8.942607191797026e-7), HFloat(0.16310549685859163)]

 

[HFloat(-0.11319869588805886), HFloat(-8.133516579444944e-5), HFloat(5.388903003794201e-5), HFloat(0.18048096803030883)]

 



 k         DEP__pi          DEQ__pi          DER__pi             beta

0.10    8.124235e-003    1.324435e-006    8.942607e-007    1.631055e-001
0.12    7.612606e-003    9.129944e-007   -1.005420e-006    1.650366e-001
0.14    7.942559e-002    4.729956e-005    1.622852e-004    1.669568e-001
0.16    3.069396e-001    1.945506e-004   -3.926488e-004    1.689244e-001
0.18   -4.559813e-002   -3.429199e-005   -2.476548e-005    1.708311e-001
0.22   -1.622543e-002   -1.491153e-005    6.926161e-005    1.746870e-001
0.24    1.663421e-003    5.050235e-008    4.267943e-006    1.766222e-001
0.26   -8.794443e-004   -4.779734e-006   -3.894070e-006    1.785537e-001
0.28   -1.131987e-001   -8.133517e-005    5.388903e-005    1.804810e-001
0.30    7.856244e-003    1.410988e-006   -6.168876e-005    1.824194e-001
0.32    6.452105e-001    4.175094e-004    1.243250e-004    1.843385e-001
0.34   -8.884629e-003   -6.830507e-006    1.669743e-005    1.862763e-001
0.38    2.951367e-002    1.540137e-005    1.012055e-005    1.901387e-001
0.40    5.357337e-003   -1.042016e-006   -1.274846e-001    2.000000e-001

 

#
# Generate the maximum value in each column of the above
#
  seq
  ( max
    ( seq
      ( myName[j][k],
        j in  sort
              ( [ indices
                  ( myName,
                    'nolist'
                  )
                ]
              )
      )
    ),
    k=1..4
  );

HFloat(0.6452104791587772), HFloat(4.175094494591747e-4), HFloat(1.6228524282297182e-4), HFloat(0.2)

(1)

 


 

Download optProb3.mw

the attached?

restart:
M:=5:
f2:=j->C[j-1,M](t);
phi:=Vector(M+1, f2);
diff(phi, t);

f2 := proc (j) options operator, arrow; C[j-1, M](t) end proc

 

Vector(6, {(1) = C[0, 5](t), (2) = C[1, 5](t), (3) = C[2, 5](t), (4) = C[3, 5](t), (5) = C[4, 5](t), (6) = C[5, 5](t)})

 

Vector[column](%id = 18446744074379058582)

(1)

 

Download vecDiff.mw

that it is hard to know were to start!

  1. Your code contains a mixture of "active" and "inert" commands: I am assumed that most of the latter should actually be the former
  2. Multiple function definitions which do not depend on the passed argument - I mean why??
  3. Use of the symbol for 'Pi' as an argument in many function definitions - just don't
  4. A persistent pop-up for the interactive Plot Builder - why?

So I made a *lot* of guesses about what you actually intended, and came up with the attached. I have no doubt that some of my guesses may be wrong so you should read the attached very carefully.

The NLPsolve(..,maximise) command *failed* for a couple of values for the loop index. I didn't bother to work out why: just "filtered" these cases with a try-catch construct.

The achieved value of the maximum doesn't vary very much, and is always obtained for more or les the same values of the variables 'p' and 'q'. The value of the variable 'r' to produce the maximum does however vary with loop index.

restart;
with(Optimization):
G:=a-b*p:
z:=q-G:
M:=int((z-u)*f(u), u=-3500..z):
N:=int((u-z)*f(u), u=z..1500):
beta:=alpha*K+(1-K)*r/p:
E__pi:=(p-c)*(G+mu)-(c-v)*M-(p-c+s-beta*(p-r-c-d+s))*N:
EXE__pi := eval( E__pi,
                 [ c = 35,
                   a = 100000,
                   b = 1500,
                   mu = -1000,
                   v = 10,
                   d = 3,
                   s = 3,
                   f(u)= exp((-1/800)*(u+1000)*(u+1000))/sqrt(2*3.14*800)
                 ]
               ):
DEP__pi:=diff(EXE__pi, p):
DEQ__pi:=diff(EXE__pi, q):
DER__pi:=diff(EXE__pi, r):
printf( "%2s %14s %13s %13s %13s\n\n",
        "k", "maximum", "p", "q", "r"
      );
for k from 0.1 by 0.02 to 0.40 do
    E1__pi:=eval(EXE__pi,[alpha = 0.5, K=k]):
    #printf("%a   ", k);
    try  ans:= NLPSolve
               ( E1__pi,
                 p = 40 .. 60,
                 q = 15000 .. 26000,
                 r = 0 .. 25,
                 initialpoint = {p = 50, q = 15000, r = 0},
                 maximize
               ):
         printf( "%4.2f   %8.6e   %8.6e   %8.6e   %8.6e \n",
                 k, ans[1], rhs~(ans[2])[]
               );
    catch "Error, (in Optimization:-NLPSolve) no improved point could be found":
          printf("\n**NLPSolve() failed when k=%4.2f**\n\n", k);
    end try:
    myName := table( eval( [ aa = DEP__pi,
                             bb = DEQ__pi,
                             cc = DER__pi,
                             dd = beta
                           ],
                           [ alpha = .5,
                             K = k,
                             p = 50.2439391403638,
                             q = 23142.7537807761,
                             r = 6.22630454447208
                           ]
                         )
                   ):
od:

 k        maximum             p             q             r

0.10   3.601447e+05   5.049785e+001   2.324840e+004   6.346205e+000
0.12   3.601452e+05   5.049785e+001   2.324835e+004   6.027413e+000
0.14   3.601458e+05   5.049785e+001   2.324830e+004   5.693151e+000
0.16   3.601464e+05   5.049785e+001   2.324824e+004   5.345824e+000
0.18   3.601470e+05   5.049786e+001   2.324818e+004   4.977804e+000

**NLPSolve() failed when k=0.20**

0.22   3.601484e+05   5.049786e+001   2.324804e+004   4.187889e+000
0.24   3.601491e+05   5.049786e+001   2.324797e+004   3.762237e+000
0.26   3.601499e+05   5.049785e+001   2.324789e+004   3.313322e+000
0.28   3.601508e+05   5.049785e+001   2.324781e+004   2.839169e+000
0.30   3.601517e+05   5.049785e+001   2.324772e+004   2.338727e+000
0.32   3.601526e+05   5.049785e+001   2.324764e+004   1.807411e+000
0.34   3.601537e+05   5.049785e+001   2.324753e+004   1.245333e+000

**NLPSolve() failed when k=0.36**

0.38   3.601560e+05   5.049784e+001   2.324731e+004   1.129764e-002
0.40   3.601572e+05   5.049786e+001   2.324717e+004   0.000000e+000

 

 

Download optProb.mw

but if I fix a few syntax errors, then I can plot X[i]/f(eta) for any value of X[i]. See the attached. Now what exactly is it that you want to know about this ode system?

As usual, plots look a lot more interesting in a Maple worksheet than they do when rendered on this site - II have no idea why this happens, but I encourage you to download and re-execute

  restart;
  with(plots):
  fcns := {T(eta), f(eta)}:
  ep:= .1: M := 1: kp := .5: n := 1:
  ec:= .1: pr := 1: s := .1: N := 5:
  sys:= diff(f(eta),eta$3)+f(eta)*diff(f(eta),eta$2)-diff(f(eta),eta)*diff(f(eta),eta)+ep*ep+(M+1/kp)*(ep-diff(f(eta),eta)) = 0,
        diff(T(eta),eta$2)+pr*(f(eta)*diff(T(eta),eta)-n*diff(f(eta),eta)*T(eta))+pr*(ec*diff(f(eta),eta$2)*diff(f(eta), eta$2)+ec*(M+1/kp)*diff(f(eta),eta)^2+s*T(eta)) = 0:
  bc:= f(0)=0, D(f)(0)=1, D(f)(N) = ep, T(0) = 1, T(N) = 0:
  R:= dsolve(eval({bc, sys}), numeric):
  psi := [-0.9e-1, -0.7e-1, -0.4e-1, -0.1e-1, 0, 0.1e-1, 0.4e-1, 0.7e-1, 0.9e-1]:
  for i to 9 do
      plt[i]:=odeplot( R, [eta, psi[i]/f(eta)], eta=0..5);
  end do:
  display( [seq(plt[i], i=1..9)]);

 

 

Download odeProb.mw

First 121 122 123 124 125 126 127 Last Page 123 of 207