tomleslie

4993 Reputation

15 Badges

9 years, 211 days

MaplePrimes Activity


These are answers submitted by tomleslie

has two problems (at least)

I have highlighted both of these in the attached

  restart;
  with(DEtools):
  eq1:= (D(x))(t) = -y(t);
  eq2:= (D(y))(t) = x(t)+2*x(t)^3-signum(z(t));
  eq3:= (D(z))(t) = w(t);
  eq4:= (D(w))(t) = -z(t)*(1+6*x(t)^2);
  sys:= eq1, eq2, eq3, eq4;
  ic1:= [ x(0)=0, y(0)=0, z(0)=cos(1), w(0)=sin(1)];
  ic2:= [ x(0)=0, y(0)=0, z(0)=cos(2.5), w(0)=sin(2.5)];
  ic:= ic1, ic2;
  DEplot( [sys],
          [x(t), y(t), z(t), w(t)],
           t = 0 .. 10,
           [ic],
           stepsize = 0.5e-1,
           scene = [x(t), y(t)],
           linecolor = [blue, red]
        );
  sol1:= dsolve
         ( { sys, x(0)=0, y(0)=0, z(0)=cos(1), w(0)=sin(1)},
           { x(t), y(t), z(t), w(t)},
           type=numeric
         );
  T:= 10.0;
  N:= 100;
  h:= T/N;
  xk:= 0;
  for k from 1 to N do
      solk:= sol1(k*h);
      xknew:= subs(solk,x(t));
      yknew:= subs(solk,y(t));
      if   xk*xknew<=0 and abs(yknew-6)<0.5
      then break
      fi;
  xk:= xknew;
  od:
  sol1(k*h):

  temps:= proc(alpha,eps)
                local sol, solk, T, N, h ,k, xk, xknew,
                      yknew, t0, t1, tm, x0, x1, xm;
                sol:= dsolve
                       ( { sys, x(0)=0, y(0)=0, z(0)=cos(alpha) ,w(0)=sin(alpha) },
                         { x(t), y(t), z(t), w(t)},
                         type=numeric
                       );
                T:= 10.0;
                N:= 100;
                h:= T/N;
                xk:= 0;
                for k from 1 to N do
                    solk:= sol(k*h);
                    xknew:= subs(solk, x(t));
                    yknew:= subs(solk, y(t));
                    if   xk*xknew<=0 and abs(yknew-6)<0.5
                    then break
                    fi;
                    xk:= xknew;
                od;
                t0:= (k-1)*h;
                t1:= k*h;
                x0:= subs(sol(t0), x(t));
                x1:= subs(sol(t1), x(t));
                while abs(x0-x1)>eps do
                      tm:= (t0+t1)/2;
                      xm:= subs(sol(tm), x(t));
                      if   xm*x0<0
                      then x1:= xm;
                           t1:= tm;
                      else x0:= xm;
                           t0:= tm;
                      fi;
                od;
                return t0;
           end:
  dicho:= proc(eps)
                local a, b, m, sola, solb, solm,
                      ta, tb, tm, ya, yb, ym;
                a:= 1;
                b:= 2.5;
                sola:= dsolve
                        ( {sys, x(0)=0, y(0)=0, z(0)=cos(a), w(0)=sin(a)},
                          {x(t),y(t),z(t),w(t)},
                          type=numeric
                        );
                solb:= dsolve
                        ( {sys, x(0)=0, y(0)=0, z(0)=cos(b), w(0)=sin(b)},
                          {x(t), y(t), z(t), w(t)},
                          type=numeric
                        );
                ta:= temps(a,eps);
                tb:= temps(b,eps);
                ya:= subs(sola(ta),y(t));
                yb:= subs(solb(tb),y(t));
                while abs(yb-ya)>eps do
                      m:= evalf((a+b)/2);
                      solm:= dsolve
                              ( { sys, x(0)=0, y(0)=0, z(0)=cos(m), w(0)=sin(m)},
                                {x(t), y(t), z(t), w(t)},
                                type=numeric
                              );
                      tm:= temps(m,eps);
                      # yb:= subs(sol(tm),y(t)); # should this be sola, solb or
                                                 # solm?? Used solm() just to
                                                 # eliminate the error This is
                                                 # quite likely to be incorrect
                      yb:= subs(solm(tm),y(t));
                      if   (ym-6)*(ya-6)<0 # first time through this loop ym is
                                           # not initialized In fact it is
                                           # *never* initialized - although all
                                           # sorts of stuff depends on it.
                                           # WTF is ym - I have no idea!!
                      then b:= m;
                           yb:= ym;
                      else a:= m;
                           ya:= ym;
                      fi;

                od;
                return a;
            end:
  dicho(0.01);
  temps(2.136718750,0.01);

(D(x))(t) = -y(t)

 

(D(y))(t) = x(t)+2*x(t)^3-signum(z(t))

 

(D(z))(t) = w(t)

 

(D(w))(t) = -z(t)*(1+6*x(t)^2)

 

(D(x))(t) = -y(t), (D(y))(t) = x(t)+2*x(t)^3-signum(z(t)), (D(z))(t) = w(t), (D(w))(t) = -z(t)*(1+6*x(t)^2)

 

[x(0) = 0, y(0) = 0, z(0) = cos(1), w(0) = sin(1)]

 

[x(0) = 0, y(0) = 0, z(0) = -.8011436155, w(0) = .5984721441]

 

[x(0) = 0, y(0) = 0, z(0) = cos(1), w(0) = sin(1)], [x(0) = 0, y(0) = 0, z(0) = -.8011436155, w(0) = .5984721441]

 

 

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) = 4, (2) = 4, (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.5047658755841546e-2, (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..4, {(1) = .841470984807897, (2) = .0, (3) = .0, (4) = .54030230586814}, 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..4, {(1) = .1, (2) = .1, (3) = .1, (4) = .1}, datatype = float[8], order = C_order), Array(1..4, {(1) = .0, (2) = .0, (3) = .0, (4) = .0}, datatype = float[8], order = C_order), Array(1..4, {(1) = .0, (2) = .0, (3) = .0, (4) = .0}, datatype = float[8], order = C_order), Array(1..4, {(1) = .0, (2) = .0, (3) = .0, (4) = .0}, datatype = float[8], order = C_order), Array(1..4, {(1) = .0, (2) = .0, (3) = .0, (4) = .0}, datatype = float[8], order = C_order), Array(1..4, 1..4, {(1, 1) = .0, (1, 2) = .0, (1, 3) = .0, (1, 4) = .0, (2, 1) = .0, (2, 2) = .0, (2, 3) = .0, (2, 4) = .0, (3, 1) = .0, (3, 2) = .0, (3, 3) = .0, (3, 4) = .0, (4, 1) = .0, (4, 2) = .0, (4, 3) = .0, (4, 4) = .0}, datatype = float[8], order = C_order), Array(1..4, 1..4, {(1, 1) = .0, (1, 2) = .0, (1, 3) = .0, (1, 4) = .0, (2, 1) = .0, (2, 2) = .0, (2, 3) = .0, (2, 4) = .0, (3, 1) = .0, (3, 2) = .0, (3, 3) = .0, (3, 4) = .0, (4, 1) = .0, (4, 2) = .0, (4, 3) = .0, (4, 4) = .0}, datatype = float[8], order = C_order), Array(1..4, {(1) = .0, (2) = .0, (3) = .0, (4) = .0}, datatype = float[8], order = C_order), Array(1..4, 1..4, {(1, 1) = .0, (1, 2) = .0, (1, 3) = .0, (1, 4) = .0, (2, 1) = .0, (2, 2) = .0, (2, 3) = .0, (2, 4) = .0, (3, 1) = .0, (3, 2) = .0, (3, 3) = .0, (3, 4) = .0, (4, 1) = .0, (4, 2) = .0, (4, 3) = .0, (4, 4) = .0}, datatype = float[8], order = C_order), Array(1..4, 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, (3, 1) = .0, (3, 2) = .0, (3, 3) = .0, (3, 4) = .0, (3, 5) = .0, (3, 6) = .0, (4, 1) = .0, (4, 2) = .0, (4, 3) = .0, (4, 4) = .0, (4, 5) = .0, (4, 6) = .0}, datatype = float[8], order = C_order), Array(1..4, {(1) = 0, (2) = 0, (3) = 0, (4) = 0}, datatype = integer[8]), Array(1..4, {(1) = .0, (2) = .0, (3) = .0, (4) = .0}, datatype = float[8], order = C_order), Array(1..4, {(1) = .0, (2) = .0, (3) = .0, (4) = .0}, datatype = float[8], order = C_order), Array(1..4, {(1) = .0, (2) = .0, (3) = .0, (4) = .0}, datatype = float[8], order = C_order), Array(1..4, {(1) = .0, (2) = .0, (3) = .0, (4) = .0}, datatype = float[8], order = C_order), Array(1..4, {(1) = .0, (2) = .0, (3) = .0, (4) = .0}, datatype = float[8], order = C_order), Array(1..8, {(1) = .0, (2) = .0, (3) = .0, (4) = .0, (5) = .0, (6) = .0, (7) = .0, (8) = .0}, datatype = float[8], order = C_order), Array(1..4, {(1) = 0, (2) = 0, (3) = 0, (4) = 0}, datatype = integer[8])]), ( 8 ) = ([Array(1..4, {(1) = .841470984807897, (2) = .0, (3) = .0, (4) = .54030230586814}, datatype = float[8], order = C_order), Array(1..4, {(1) = .0, (2) = .0, (3) = .0, (4) = .0}, datatype = float[8], order = C_order), Array(1..4, {(1) = -.54030230586814, (2) = -.0, (3) = -1.0, (4) = .841470984807897}, datatype = float[8], order = C_order), 0, 0]), ( 11 ) = (Array(1..6, 0..4, {(1, 1) = .0, (1, 2) = .0, (1, 3) = .0, (1, 4) = .0, (2, 0) = .0, (2, 1) = .0, (2, 2) = .0, (2, 3) = .0, (2, 4) = .0, (3, 0) = .0, (3, 1) = .0, (3, 2) = .0, (3, 3) = .0, (3, 4) = .0, (4, 0) = .0, (4, 1) = .0, (4, 2) = .0, (4, 3) = .0, (4, 4) = .0, (5, 0) = .0, (5, 1) = .0, (5, 2) = .0, (5, 3) = .0, (5, 4) = .0, (6, 0) = .0, (6, 1) = .0, (6, 2) = .0, (6, 3) = .0, (6, 4) = .0}, datatype = float[8], order = C_order)), ( 10 ) = ([proc (N, X, Y, YP) option `[Y[1] = w(t), Y[2] = x(t), Y[3] = y(t), Y[4] = z(t)]`; YP[1] := -Y[4]*(6*Y[2]^2+1); YP[2] := -Y[3]; YP[3] := Y[2]+2*Y[2]^3-signum(Y[4]); YP[4] := Y[1]; 0 end proc, -1, 0, 0, 0, 0, 0, 0, 0, 0]), ( 13 ) = (), ( 12 ) = (), ( 15 ) = ("rkf45"), ( 14 ) = ([0, 0]), ( 18 ) = ([]), ( 19 ) = (0), ( 16 ) = ([0, 0, 0, 0, 0, []]), ( 17 ) = ([proc (N, X, Y, YP) option `[Y[1] = w(t), Y[2] = x(t), Y[3] = y(t), Y[4] = z(t)]`; YP[1] := -Y[4]*(6*Y[2]^2+1); YP[2] := -Y[3]; YP[3] := Y[2]+2*Y[2]^3-signum(Y[4]); YP[4] := Y[1]; 0 end proc, -1, 0, 0, 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..4, {(1) = 0., (2) = .841470984807897, (3) = 0., (4) = 0.}); _vmap := array( 1 .. 4, [( 1 ) = (1), ( 2 ) = (2), ( 3 ) = (3), ( 4 ) = (4)  ] ); _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); _i := false; if _par <> [] then _i := `dsolve/numeric/process_parameters`(_n, _pars, _par, _y0) end if; if _ini <> [] then _i := `dsolve/numeric/process_initial`(_n-_ne, _ini, _y0, _pars, _vmap) or _i end if; if _i then `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 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]; if type(_EnvDSNumericSaveDigits, 'posint') then _dat[4][26] := _EnvDSNumericSaveDigits else _dat[4][26] := Digits end if; _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, w(t), x(t), y(t), z(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

 

10.0

 

100

 

.1000000000

 

0

 

Error, (in dicho) cannot determine if this expression is true or false: -HFloat(0.17348797556887252)*ym < HFloat(-1.0409278534132351)

 

8.737500000

(1)

 

Download procprobs.mw

I understand correctly, then you want something like the attached

  restart;
#
# Define the functions
#
#      u(t,f) and
#      x(t,f)
#
  u:= unapply
      ( 1-(8*(10.3968*t^2-5.8368*t*f-.229376*f^2-5.1984))/(4.56*t^2-2.56*t*f+.8192*f^2+2.28)^2,
        [t,f]
      ):
  x:= unapply
      ( f+t-(8*(-2.28*t+.64*f))/(2.28+2*(-t+.64*f)^2+2.56*t^2),
        [t,f]
       ):
#
# Plot u(0,f) against x(0,f)
#
  plot( [x(0,f), u(0,f), f=-5..5]);
#
# Plot u(t,f) against x(t,f) and t
#
  plot3d([ x(t,f), t, u(t,f) ], f=-5..5, t=-5..5);

 

 

 


 

Download somePlots.mw

For details, see the attached.

Short version is that your procedure calls two functions 'f()' and 'check()' which are defined nowhere so procedure is guaranteed to fail, unless these 'unidentified' functions exist elsewhere(probably top-level)  in your code.

The "debug" icon in the toolbar is only really intended for to work with currenlty running operations - so if some code seems to be taking "forever" to execute then this will give you a kind of "interrupt" whihmay help you to figure out what it is currently doing and why. I actually find this facility pretty much useless for code which fails "quickly".

The best way to work out how to use the debugger (beware it isn't very user-friendly!) is to read the Maple Programming Guide available here, and experiment with the examples

https://www.maplesoft.com/support/help/Maple/view.aspx?path=ProgrammingGuide/Chapter16

(This document used to be available as a pdf (easier to download and study, in my opinion) but I can' figure out where the pdf link is

f1:=  proc(n)
          local x, y, i, rx, ry, dumbindex:= 1,
                xdumb, ydumb, d:= 0.00197241, flag:= 1,
                p, xl, yl, temp, xg, yg;
          xdumb[1]:= n:
          ydumb[1]:= n:  
          for i from 1 to  n do    
              while (d>0.0019724 or flag=1) do
                  #
                  # Why is a new random number generator
                  # being instantiated every time this
                  # loop executes?
                  # Surely better would be to initialise
                  # the first RNG outside both loops, call
                  # and run the calls to it in the outer
                  # - or maybe not?? Even if a couple of
                  # 'new' random numbers are needed every
                  # the 'inner' loop runs, it is probably
                  # a better idea to inilis the generators
                  # in the outer loop and only have the
                  # 'calls' here
                  #   
                    rx:= rand(1..n):
                    x[i]:= rx():
                    ry:= rand(x[i]..n):
                    y[i]:= ry():
                  #
                  # What does the following command do??
                  # There is a command called 'check()'
                  # in the Physics() package, but since
                  # the latter has not been loaded(?)
                  # the check() call here will never return
                  # anything other than an unevaluated
                  # function call??
                  #
                  # Doesn't look like right!
                  #
                    flag:= check(x[i],y[i],xdumb,ydumb,dumbindex):  
                    if   flag=1
                    then dumbindex:= dumbindex+1;
                         xdumb[dumbindex]:= x[i]:
                         ydumb[dumbindex]:= y[i]:
                    fi:
                  #
                  # What does the next command do??
                  #
                  # The function 'f()' is undefined so will
                  # never return anything other than its
                  # literal name, which is a single value.
                  # Therefore no way that a duplicate
                  # assignment will work, because lhs has
                  # two names, 'p' and 'd', and rhs only has
                  # one (unevaluated) value.
                  #
                  # Since both 'p' and 'd' are used in this
                  # code - this statement is probably not a
                  # good idea
                  #
                  # I did consider that this *might* be a
                  # recursive call - ie calling this procedure
                  # with new arguments, but since this
                  # procedure is called 'f1' and accepts one
                  # argument, and the invocation calls 'f'
                  # and supplies two arguments this interpretation
                  # is almost certainly incorrect
                  #
                  # The mismatch between the returned
                  # (unevaluated) single value and the dual
                  # assignment is what causes the error message
                  # whenever the prodedure 'f1()' is invoked
                  # 
                    p, d:= f(x[i],y[i]):
              end:  
              xl[i]:= x[i]:
              yl[i]:= y[i]:  
              if   i=1
              then temp:= p:
                   xg:= x[i]:
                   yg:= y[i];  
              else if   p<temp
                   then temp:= p:
                        xg:= x[i]:
                        yg:= y[i] ;
                   fi:  
              fi:
          end do:  
          return xg,yg:  

end proc;

proc (n) local x, y, i, rx, ry, dumbindex, xdumb, ydumb, d, flag, p, xl, yl, temp, xg, yg; dumbindex := 1; d := 0.197241e-2; flag := 1; xdumb[1] := n; ydumb[1] := n; for i to n do while 0.19724e-2 < d or flag = 1 do rx := rand(1 .. n); x[i] := rx(); ry := rand(x[i] .. n); y[i] := ry(); flag := check(x[i], y[i], xdumb, ydumb, dumbindex); if flag = 1 then dumbindex := dumbindex+1; xdumb[dumbindex] := x[i]; ydumb[dumbindex] := y[i] end if; p, d := f(x[i], y[i]) end do; xl[i] := x[i]; yl[i] := y[i]; if i = 1 then temp := p; xg := x[i]; yg := y[i] else if p < temp then temp := p; xg := x[i]; yg := y[i] end if end if end do; return xg, yg end proc

(1)

f1(10);

Error, (in f1) mismatched multiple assignment of 2 variables on the left side and 1 value on the right side

 

 

Download procProb.mw

whihc are pretty simple to fix. However a more serious problem is in the form of the boundary conditions which you are using. You are only allowed derivatives which are "normal" to the boundary. You have two,

D[2](C)(0, t) = 0, D[2](C)(250, t) = 0

which are not! These can never be used

An alternative is that you have misinterpreted how to apply the operator 'D'. The two boundary conditions above mean

  1. Obtain the first derivative with respct to the second variable (ie 't')
  2. Evaluate the results of (1) at (0,t) and (250,t)

On the other hand if you had intended to obtain the second derivative with respect to the first variable, this would be written

D[1,1](C)(0, t) = 0, D[1,1](C)(250, t) = 0

These derivatives are "normal" to the boundary and so pdsolve/numeric will provide a solution

I have used this changed interpretation in the final two execution groups of the attached, which now works without error. However a quick check on a few values indicates that the result isn't numerically very stable. When t>~0.15 values start to grow very  rapidly

restart

with(plots)

with(CurveFitting)

pts := [Vector[row](99, {(1) = 0, (2) = 3.016315859, (3) = 5.753536424, (4) = 8.489713643, (5) = 11.22797756, (6) = 13.96519812, (7) = 16.09414745, (8) = 18.83136802, (9) = 21.26445296, (10) = 24.00167353, (11) = 26.73889409, (12) = 29.47611466, (13) = 31.60506399, (14) = 34.34228455, (15) = 37.07950512, (16) = 39.51259007, (17) = 41.6415394, (18) = 44.37875996, (19) = 46.81184491, (20) = 49.54906547, (21) = 51.6780148, (22) = 54.11109975, (23) = 56.84832032, (24) = 58.97726964, (25) = 62.32276145, (26) = 64.45171078, (27) = 66.88479572, (28) = 69.01374505, (29) = 71.44578665, (30) = 74.1814422, (31) = 76.91814109, (32) = 79.0455254, (33) = 81.47704533, (34) = 84.21165752, (35) = 86.33695514, (36) = 88.76691004, (37) = 90.89116431, (38) = 93.3195542, (39) = 96.04894966, (40) = 98.17059556, (41) = 100.5958554, (42) = 103.3231642, (43) = 105.4432451, (44) = 107.8679832, (45) = 110.5947703, (46) = 113.3236441, (47) = 116.0514746, (48) = 118.1746855, (49) = 120.9066893, (50) = 125.4640285, (51) = 127.8960701, (52) = 130.634334, (53) = 132.763805, (54) = 135.1994984, (55) = 137.9382839, (56) = 140.06932, (57) = 142.5034483, (58) = 145.2411905, (59) = 147.976846, (60) = 150.7119799, (61) = 153.4450271, (62) = 156.1770309, (63) = 158.9069481, (64) = 161.9399575, (65) = 164.6693529, (66) = 167.0951345, (67) = 169.2178237, (68) = 171.9472192, (69) = 174.3756091, (70) = 176.4998633, (71) = 179.2334322, (72) = 181.9680444, (73) = 184.4011293, (74) = 186.531122, (75) = 189.2719943, (76) = 192.0149532, (77) = 194.4542983, (78) = 197.2014306, (79) = 201.7822452, (80) = 203.921628, (81) = 207.5889923, (82) = 210.3397763, (83) = 213.699875, (84) = 217.3651526, (85) = 220.1133283, (86) = 222.859939, (87) = 224.9961918, (88) = 227.7412375, (89) = 230.1795391, (90) = 232.3131835, (91) = 234.7504419, (92) = 237.4913141, (93) = 240.5368437, (94) = 242.9720153, (95) = 245.7108009, (96) = 247.8313153, (97) = 247.8413153, (98) = 247.8513153, (99) = 250}), Vector[row](99, {(1) = -0.41150436e-1, (2) = -0.41150436e-1, (3) = -0.4113729e-1, (4) = -0.38722776e-1, (5) = -0.41110998e-1, (6) = -0.41097851e-1, (7) = -0.41087627e-1, (8) = -0.4107448e-1, (9) = -0.41062795e-1, (10) = -0.41049649e-1, (11) = -0.41036503e-1, (12) = -0.41023356e-1, (13) = -0.41013132e-1, (14) = -0.40999985e-1, (15) = -0.40986839e-1, (16) = -0.40975154e-1, (17) = -0.40964929e-1, (18) = -0.40951783e-1, (19) = -0.40940097e-1, (20) = -0.40926951e-1, (21) = -0.40916726e-1, (22) = -0.40905041e-1, (23) = -0.40891895e-1, (24) = -0.4088167e-1, (25) = -0.40865602e-1, (26) = -0.40855378e-1, (27) = -0.40843692e-1, (28) = -0.40833467e-1, (29) = -0.38420415e-1, (30) = -0.34805218e-1, (31) = -0.33591388e-1, (32) = -0.29979112e-1, (33) = -0.26365376e-1, (34) = -0.20348812e-1, (35) = -0.11933802e-1, (36) = -0.4718015e-2, (37) = 0.6098363e-2, (38) = 0.169162e-1, (39) = 0.34939601e-1, (40) = 0.51759396e-1, (41) = 0.69781335e-1, (42) = 0.9260747e-1, (43) = .113029316, (44) = .132251939, (45) = .156278757, (46) = .175502841, (47) = .197128292, (48) = .210346036, (49) = .222366019, (50) = .233194081, (51) = .235607134, (52) = .233218913, (53) = .232028454, (54) = .226036722, (55) = .222447817, (56) = .217655307, (57) = .215265626, (58) = .214078088, (59) = .217693285, (60) = .222509166, (61) = .232127781, (62) = .244147763, (63) = .26097048, (64) = .280196024, (65) = .298219424, (66) = .31504068, (67) = .329459108, (68) = .347482508, (69) = .358300346, (70) = .369116723, (71) = .377534655, (72) = .383551219, (73) = .383562904, (74) = .381171762, (75) = .372780123, (76) = .35958575, (77) = .345189232, (78) = .32238939, (79) = .27918669, (80) = .255183243, (81) = .214377529, (82) = .183172901, (83) = .149569828, (84) = .113566848, (85) = 0.88365639e-1, (86) = 0.6676648e-1, (87) = 0.49967135e-1, (88) = 0.31970027e-1, (89) = 0.19974876e-1, (90) = 0.9178949e-2, (91) = -0.414835e-3, (92) = -0.8806474e-2, (93) = -0.18397336e-1, (94) = -0.23188385e-1, (95) = -0.26777289e-1, (96) = -0.30369115e-1, (97) = -0.30369115e-1, (98) = -0.30369115e-1, (99) = -0.30369115e-1})]

A := unapply(Spline(pts[1], pts[2], x, degree = 3), x)

PDE := diff(C(x, t), t) = diff(C(x, t), x, x)-(diff(C(x, t), x))+5*(diff(C(x, t), x, x, x, x))

IBC := C(x, 0) = A(x), (D[1](C))(0, t) = 0, (D[1](C))(250, t) = 0, (D[2](C))(0, t) = 0, (D[2](C))(250, t) = 0

pds := pdsolve(PDE, [IBC], numeric, time = t, range = 0 .. 250, timestep = 0.5e-2, spacestep = 1)

Error, (in pdsolve/numeric/process_IBCs) initial/boundary conditions can only contain derivatives which are normal to the boundary, got (D[2](C))(0, t)

 

IBC := C(x, 0) = A(x), (D[1](C))(0, t) = 0, (D[1](C))(250, t) = 0, (D[1, 1](C))(0, t) = 0, (D[1, 1](C))(250, t) = 0; pds := pdsolve(PDE, [IBC], numeric, time = t, range = 0 .. 250, timestep = 0.5e-2, spacestep = 1)
 

_m656127456

(1)

solt := pds:-value(x = 125, t = 0 .. 1)
solt(.1)
solt(.2)
solt(.3)
solt(.4)

solt(.5); pds:-plot3d(x = 0 .. 250, t = 0 .. .15)

proc (x_pde) local res, solnproc, outpoint, ndsol, stype, i; option `Copyright (c) 2001 by Waterloo Maple Inc. All rights reserved.`; Digits := trunc(evalhf(Digits)); outpoint := evalf(x_pde); solnproc := proc (outpoint) local indepvals, depvals, vary, ndep, i; option `Copyright (c) 2001 by Waterloo Maple Inc. All rights reserved.`; table( [( "soln_procedures" ) = array( 0 .. 0, [( 0 ) = (18446744074405474742)  ] ) ] ) indepvals := Vector(201, {(1) = .0, (2) = 0.50e-2, (3) = 0.1e-1, (4) = 0.15e-1, (5) = 0.2e-1, (6) = 0.25e-1, (7) = 0.3e-1, (8) = 0.35e-1, (9) = 0.4e-1, (10) = 0.45e-1, (11) = 0.5e-1, (12) = 0.55e-1, (13) = 0.6e-1, (14) = 0.65e-1, (15) = 0.7e-1, (16) = 0.75e-1, (17) = 0.8e-1, (18) = 0.85e-1, (19) = 0.9e-1, (20) = 0.95e-1, (21) = .1, (22) = .105, (23) = .11, (24) = .115, (25) = .12, (26) = .125, (27) = .13, (28) = .135, (29) = .14, (30) = .145, (31) = .15, (32) = .155, (33) = .16, (34) = .165, (35) = .17, (36) = .175, (37) = .18, (38) = .185, (39) = .19, (40) = .195, (41) = .2, (42) = .205, (43) = .21, (44) = .215, (45) = .22, (46) = .225, (47) = .23, (48) = .235, (49) = .24, (50) = .245, (51) = .25, (52) = .255, (53) = .26, (54) = .265, (55) = .27, (56) = .275, (57) = .28, (58) = .285, (59) = .29, (60) = .295, (61) = .3, (62) = .305, (63) = .31, (64) = .315, (65) = .32, (66) = .325, (67) = .33, (68) = .335, (69) = .34, (70) = .345, (71) = .35, (72) = .355, (73) = .36, (74) = .365, (75) = .37, (76) = .375, (77) = .38, (78) = .385, (79) = .39, (80) = .395, (81) = .4, (82) = .405, (83) = .41, (84) = .415, (85) = .42, (86) = .425, (87) = .43, (88) = .435, (89) = .44, (90) = .445, (91) = .45, (92) = .455, (93) = .46, (94) = .465, (95) = .47, (96) = .475, (97) = .48, (98) = .485, (99) = .49, (100) = .495, (101) = .5, (102) = .505, (103) = .51, (104) = .515, (105) = .52, (106) = .525, (107) = .53, (108) = .535, (109) = .54, (110) = .545, (111) = .55, (112) = .555, (113) = .56, (114) = .565, (115) = .57, (116) = .575, (117) = .58, (118) = .585, (119) = .59, (120) = .595, (121) = .6, (122) = .605, (123) = .61, (124) = .615, (125) = .62, (126) = .625, (127) = .63, (128) = .635, (129) = .64, (130) = .645, (131) = .65, (132) = .655, (133) = .66, (134) = .665, (135) = .67, (136) = .675, (137) = .68, (138) = .685, (139) = .69, (140) = .695, (141) = .7, (142) = .705, (143) = .71, (144) = .715, (145) = .72, (146) = .725, (147) = .73, (148) = .735, (149) = .74, (150) = .745, (151) = .75, (152) = .755, (153) = .76, (154) = .765, (155) = .77, (156) = .775, (157) = .78, (158) = .785, (159) = .79, (160) = .795, (161) = .8, (162) = .805, (163) = .81, (164) = .815, (165) = .82, (166) = .825, (167) = .83, (168) = .835, (169) = .84, (170) = .845, (171) = .85, (172) = .855, (173) = .86, (174) = .865, (175) = .87, (176) = .875, (177) = .88, (178) = .885, (179) = .89, (180) = .895, (181) = .9, (182) = .905, (183) = .91, (184) = .915, (185) = .92, (186) = .925, (187) = .93, (188) = .935, (189) = .94, (190) = .945, (191) = .95, (192) = .955, (193) = .96, (194) = .965, (195) = .97, (196) = .975, (197) = .98, (198) = .985, (199) = .99, (200) = .995, (201) = 1.0}, datatype = float[8]); if outpoint = "left" then return indepvals[1] elif outpoint = "right" then return indepvals[201] elif outpoint = "start" then return 0. elif not type(outpoint, 'numeric') then error "non-numeric input" end if; if outpoint < indepvals[1] or indepvals[201] < outpoint then error "requested %1 value must be in the range %2..%3", t, indepvals[1], indepvals[201] end if; depvals := Matrix(201, 1, {(1, 1) = .232413246628474, (2, 1) = .23239616646961464, (3, 1) = .23237892149561945, (4, 1) = .23236141490948167, (5, 1) = .2323434897931939, (6, 1) = .23232489790992714, (7, 1) = .23230525303085492, (8, 1) = .2322839612653557, (9, 1) = .23226011726920248, (10, 1) = .23223234989185657, (11, 1) = .23219859299622303, (12, 1) = .2321557456601578, (13, 1) = .2320991690132882, (14, 1) = .2320219420284306, (15, 1) = .23191376193707158, (16, 1) = .23175932109117015, (17, 1) = .23153591300916146, (18, 1) = .23120990423354942, (19, 1) = .23073153820732553, (20, 1) = .2300272873116472, (21, 1) = .22898860236580862, (22, 1) = .22745537085778184, (23, 1) = .2251916062173643, (24, 1) = .2218497337485686, (25, 1) = .2169181432744511, (26, 1) = .20964419344587107, (27, 1) = .19892121087706968, (28, 1) = .1831226910920823, (29, 1) = .159859090275643, (30, 1) = .12562114400159666, (31, 1) = 0.7525687322983228e-1, (32, 1) = 0.12048672257636854e-2, (33, 1) = -.1076295508104513, (34, 1) = -.26752136365844975, (35, 1) = -.5023393514500708, (36, 1) = -.8470822500842374, (37, 1) = -1.3530591829803609, (38, 1) = -2.095478090879571, (39, 1) = -3.1845603000066034, (40, 1) = -4.781818129398978, (41, 1) = -7.12389169840764, (42, 1) = -10.557452275826186, (43, 1) = -15.59030561957488, (44, 1) = -22.96620825198311, (45, 1) = -33.77439132275213, (46, 1) = -49.60988085600682, (47, 1) = -72.80815602744363, (48, 1) = -106.78859011313051, (49, 1) = -156.55706806286457, (50, 1) = -229.4415044451341, (51, 1) = -336.1681089648402, (52, 1) = -492.43615455279945, (53, 1) = -721.2219920248788, (54, 1) = -1056.1497935929094, (55, 1) = -1546.4225910400494, (56, 1) = -2264.0354020114896, (57, 1) = -3314.3259361260116, (58, 1) = -4851.406254205843, (59, 1) = -7100.732017405288, (60, 1) = -10392.10866662953, (61, 1) = -15207.958091640898, (62, 1) = -22253.897321405224, (63, 1) = -32561.93724658056, (64, 1) = -47641.36890750351, (65, 1) = -69699.3608112794, (66, 1) = -101963.4561341752, (67, 1) = -149153.01359209075, (68, 1) = -218168.34250177347, (69, 1) = -319097.9998957051, (70, 1) = -466691.0598252868, (71, 1) = -682508.8724608892, (72, 1) = -998069.74851753, (73, 1) = -1459444.5128234343, (74, 1) = -2133971.9718518686, (75, 1) = -3120071.707069492, (76, 1) = -4561582.034637951, (77, 1) = -6668708.879653955, (78, 1) = -9748632.228128573, (79, 1) = -14250220.236218752, (80, 1) = -20829350.67995919, (81, 1) = -30444332.626956508, (82, 1) = -44495292.23948388, (83, 1) = -65027769.467461646, (84, 1) = -95030092.66599123, (85, 1) = -138867707.18261558, (86, 1) = -202917504.4328947, (87, 1) = -296494209.74511987, (88, 1) = -433203244.1939546, (89, 1) = -632916314.2805808, (90, 1) = -924656261.0146995, (91, 1) = -1350809491.2018933, (92, 1) = -1973276701.9784503, (93, 1) = -2882453448.1263504, (94, 1) = -4210342042.5680957, (95, 1) = -6149694654.252813, (96, 1) = -8981960863.284027, (97, 1) = -13118087717.81392, (98, 1) = -19158080925.650814, (99, 1) = -27977951325.649986, (100, 1) = -40856633942.19292, (101, 1) = -59661250810.27815, (102, 1) = -87117529615.9517, (103, 1) = -127204508263.99371, (104, 1) = -185730631271.21918, (105, 1) = -271174575364.423, (106, 1) = -395912419512.31616, (107, 1) = -578008629658.7682, (108, 1) = -843829830278.0294, (109, 1) = -1231859257139.5845, (110, 1) = -1798263305722.7815, (111, 1) = -2625014768434.3804, (112, 1) = -3831746752987.8916, (113, 1) = -5593050233888.452, (114, 1) = -8163714524917.53, (115, 1) = -11915557194394.293, (116, 1) = -17391163684647.662, (117, 1) = -25382298731266.78, (118, 1) = -37044314030459.68, (119, 1) = -54063073575022.8, (120, 1) = -78898499607603.4, (121, 1) = -115139902167155.5, (122, 1) = -168024389458858.94, (123, 1) = -245193192407149.5, (124, 1) = -357795069992212.56, (125, 1) = -522096044739715.25, (126, 1) = -761827773722029.8, (127, 1) = -1111613426122815.5, (128, 1) = -1621965382171542.8, (129, 1) = -2366575805863003., (130, 1) = -3452951869937000.5, (131, 1) = -5037929812363038., (132, 1) = -7350305630466803., (133, 1) = -10723846513023158., (134, 1) = -15645444023256538., (135, 1) = -22825353360197104., (136, 1) = -33299647454728544., (137, 1) = -0.485796591927218e17, (138, 1) = -0.7086995911354716e17, (139, 1) = -103386295796726416., (140, 1) = -150819335655406272., (141, 1) = -220011054523291168., (142, 1) = -0.32094128362963859e18, (143, 1) = -0.46816661382867475e18, (144, 1) = -0.68291905520500314e18, (145, 1) = -0.99616692758229901e18, (146, 1) = -0.145307911952420608e19, (147, 1) = -0.211953607618466381e19, (148, 1) = -0.30916257929399265e19, (149, 1) = -0.45094931874709509e19, (150, 1) = -0.65775384546794076e19, (151, 1) = -0.9593874728212689e19, (152, 1) = -0.13993289338661493e20, (153, 1) = -0.20409898314084835e20, (154, 1) = -0.2976852071013085e20, (155, 1) = -0.4341793648670631e20, (156, 1) = -0.6332522481430088e20, (157, 1) = -0.9235917779374206e20, (158, 1) = -0.13470361467581542e21, (159, 1) = -0.19646013145967038e21, (160, 1) = -0.28652710459022495e21, (161, 1) = -0.4178815543499227e21, (162, 1) = -0.6094484927735468e21, (163, 1) = -0.8888269870863149e21, (164, 1) = -0.12962655454894534e22, (165, 1) = -0.18904593424536497e22, (166, 1) = -0.275700415018555e22, (167, 1) = -0.402072440554644e22, (168, 1) = -0.5863650698849213e22, (169, 1) = -0.8551235441314812e22, (170, 1) = -0.1247058167028118e23, (171, 1) = -0.18186189664696205e23, (172, 1) = -0.26521248292440736e23, (173, 1) = -0.3867617591359053e23, (174, 1) = -0.5640147870305979e23, (175, 1) = -0.822498144999205e23, (176, 1) = -0.11994355352909485e24, (177, 1) = -0.17491075513956936e24, (178, 1) = -0.25506672569657314e24, (179, 1) = -0.3719536772027066e24, (180, 1) = -0.5424025583569227e24, (181, 1) = -0.7909563003856047e24, (182, 1) = -0.11534033295613543e25, (183, 1) = -0.16819300244432607e25, (184, 1) = -0.245263384414934e25, (185, 1) = -0.35764786693182256e25, (186, 1) = -0.5215269392171449e25, (187, 1) = -0.7604945285926214e25, (188, 1) = -0.1108954516862426e26, (189, 1) = -0.16170733483518643e26, (190, 1) = -0.23580016241709754e26, (191, 1) = -0.3438404169059098e26, (192, 1) = -0.5013814264278816e26, (193, 1) = -0.7311022101615126e26, (194, 1) = -0.10660719966176913e27, (195, 1) = -0.1554510291617615e27, (196, 1) = -0.22667276264437233e27, (197, 1) = -0.33052459776593336e27, (198, 1) = -0.4819555489637077e27, (199, 1) = -0.7027631412283057e27, (200, 1) = -0.10247308124056785e28, (201, 1) = -0.14942025769915007e28}, datatype = float[8], order = C_order); vary := Array(1..2, {(1) = .0, (2) = -0.50e-2}, datatype = float[8]); ndep := 1; if vary[ndep+1]-outpoint <> 0. then `pdsolve/interp1dto0d`(201, indepvals, 1, depvals, true, outpoint, vary); vary[ndep+1] := outpoint end if; [seq(vary[i], i = 1 .. ndep)] end proc; if not type(outpoint, 'numeric') then if member(outpoint, ["start", "left", "right"]) then return solnproc(x_pde) elif outpoint = "solnprocedure" then return eval(solnproc) elif procname <> unknown then return ('procname')(x_pde) else ndsol := pointto(solnproc("soln_procedures")[0]); return ('ndsol')(x_pde) end if end if; stype := "2nd"; try res := solnproc(outpoint); if stype = "1st" then [x = outpoint, t = 125., seq([C(x, t)][i] = res[i], i = 1 .. 1)] else [x = 125., t = outpoint, seq([C(x, t)][i] = res[i], i = 1 .. 1)] end if catch: error  end try end proc

 

[x = 125., t = .1, C(x, t) = HFloat(0.22898860236580862)]

 

[x = 125., t = .2, C(x, t) = HFloat(-7.12389169840764)]

 

[x = 125., t = .3, C(x, t) = HFloat(-15207.958091640898)]

 

[x = 125., t = .4, C(x, t) = HFloat(-3.0444332626956508e7)]

 

[x = 125., t = .5, C(x, t) = HFloat(-5.966125081027815e10)]

 

 

 

 

 

Download pdeProb.mw

 

 

is always worth trying.

In this case it returns'0'

See the help page at ?simplify/symbolic for the assumptions which are being made

This appears to be a duplication of the question posted here

https://www.mapleprimes.com/questions/227124-Determination-Of-Laplacian-In-A-New-Form#comment259521

under a different username - ie @9009134  rather than torabi

One odd thing about that previou thread is that my final response appears to have gone missing???

In that thread I had erroneously claimed that one could not compute the Gradient() or Laplacian() of a vector function, since these required scalar arguments.

My last post (the one that has gone missing) admitted that this assertion was an error and corrected it. My worksheet accompanying that final post shows that (using the VectorCalculus() package) one can compute the Laplacian() of a vector function, (the result is a vector), but one cannot compute the Gradient() of a vector function (technically the result is a second order tensor, aka a matrix). I pointed out that (with care) one *ought* be able to use the transpose of the Jacobian as a proxy for the Gradient() of a vector function.

This "missing" worksheet is reposted here


 

  restart;
  with(VectorCalculus):
#
# Define coordinates
#
  X := a*sinh(tau)*cos(phi)/(cosh(tau) - cos(sigma)):
  Y := a*sinh(tau)*sin(phi)/(cosh(tau) - cos(sigma)):
  Z := a*sin(sigma)/(cosh(tau) - cos(sigma)):
#
# Set up coordinate system. NB this system which the
# OP calls "toroidal" is slightly different from the
# Maple's in-built toroidal system - hence the
# coordinate system name
#
  AddCoordinates( OPToroid[ sigma,
                            tau,
                            phi
                          ],
                 [ X, Y, Z ]):
#

SetCoordinates(OPToroid[sigma, tau, phi]):
V:=VectorField( <p(sigma, tau, phi), q(sigma, tau, phi), r(sigma, tau, phi)>);

Vector(3, {(1) = p(sigma, tau, phi), (2) = q(sigma, tau, phi), (3) = r(sigma, tau, phi)})

(1)

simplify(expand(Laplacian(V)));

Vector(3, {(1) = (2*(diff(r(sigma, tau, phi), phi))*sqrt(a^2/(cosh(tau)-cos(sigma))^2)*sin(sigma)*(cosh(tau)-cos(sigma))^3*sqrt(a^2*sinh(tau)^2/(cosh(tau)-cos(sigma))^2)+((cosh(tau)-1)*(cosh(tau)+1)*(cosh(tau)-cos(sigma))^2*(diff(diff(p(sigma, tau, phi), sigma), sigma))+(cosh(tau)-1)*(cosh(tau)+1)*(cosh(tau)-cos(sigma))^2*(diff(diff(p(sigma, tau, phi), tau), tau))+(cosh(tau)-cos(sigma))^2*(diff(diff(p(sigma, tau, phi), phi), phi))-sin(sigma)*(cosh(tau)-1)*(cosh(tau)+1)*(cosh(tau)-cos(sigma))*(diff(p(sigma, tau, phi), sigma))-2*sinh(tau)*(cosh(tau)-1)*(cosh(tau)+1)*(cosh(tau)-cos(sigma))*(diff(q(sigma, tau, phi), sigma))-sinh(tau)*(cosh(tau)*cos(sigma)-1)*(cosh(tau)-cos(sigma))*(diff(p(sigma, tau, phi), tau))+2*sin(sigma)*(cosh(tau)-1)*(cosh(tau)+1)*(cosh(tau)-cos(sigma))*(diff(q(sigma, tau, phi), tau))+(-cosh(tau)^4+2*cosh(tau)^2*cos(sigma)^2-2*cos(sigma)^2+1)*p(sigma, tau, phi)+q(sigma, tau, phi)*sinh(tau)*sin(sigma)*(cosh(tau)^2-2*cosh(tau)*cos(sigma)+1))*a^2)/(a^4*sinh(tau)^2), (2) = (2*(diff(r(sigma, tau, phi), phi))*sqrt(a^2/(cosh(tau)-cos(sigma))^2)*(cosh(tau)*cos(sigma)-1)*(cosh(tau)-cos(sigma))^3*sqrt(a^2*sinh(tau)^2/(cosh(tau)-cos(sigma))^2)-(-sinh(tau)*(cosh(tau)-1)*(cosh(tau)+1)*(cosh(tau)-cos(sigma))^2*(diff(diff(q(sigma, tau, phi), sigma), sigma))-sinh(tau)*(cosh(tau)-1)*(cosh(tau)+1)*(cosh(tau)-cos(sigma))^2*(diff(diff(q(sigma, tau, phi), tau), tau))-sinh(tau)*(cosh(tau)-cos(sigma))^2*(diff(diff(q(sigma, tau, phi), phi), phi))-2*(cosh(tau)-1)^2*(cosh(tau)+1)^2*(cosh(tau)-cos(sigma))*(diff(p(sigma, tau, phi), sigma))+(cosh(tau)-1)*(cosh(tau)+1)*(cosh(tau)*cos(sigma)-1)*(cosh(tau)-cos(sigma))*(diff(q(sigma, tau, phi), tau))+sinh(tau)*sin(sigma)*(cosh(tau)-1)*(cosh(tau)+1)*(cosh(tau)-cos(sigma))*(diff(q(sigma, tau, phi), sigma))+2*sinh(tau)*sin(sigma)*(cosh(tau)-1)*(cosh(tau)+1)*(cosh(tau)-cos(sigma))*(diff(p(sigma, tau, phi), tau))+sinh(tau)*(cosh(tau)^4-cosh(tau)^2-2*cosh(tau)*cos(sigma)+cos(sigma)^2+1)*q(sigma, tau, phi)+sin(sigma)*p(sigma, tau, phi)*(cosh(tau)-1)^2*(cosh(tau)+1)^2)*a^2)/(a^4*sinh(tau)^3), (3) = -(cosh(tau)-cos(sigma))*((sinh(tau)^2*(cosh(tau)^2-sinh(tau)^2-1)*(cosh(tau)-cos(sigma))*(diff(diff(p(sigma, tau, phi), phi), sigma))+sinh(tau)^2*(cosh(tau)^2-sinh(tau)^2-1)*(cosh(tau)-cos(sigma))*(diff(diff(q(sigma, tau, phi), phi), tau))+(cosh(tau)^3*cos(sigma)+(-sinh(tau)^2-1)*cosh(tau)^2+cos(sigma)*(sinh(tau)^2-1)*cosh(tau)+sinh(tau)^4+1)*sinh(tau)*(diff(q(sigma, tau, phi), phi))+(diff(p(sigma, tau, phi), phi))*sin(sigma)*(cosh(tau)^4+sinh(tau)^4-2*cosh(tau)^2+1))*sqrt(a^2*sinh(tau)^2/(cosh(tau)-cos(sigma))^2)+((-cosh(tau)^3+cosh(tau)^2*cos(sigma)+cosh(tau)-cos(sigma))*(diff(diff(r(sigma, tau, phi), sigma), sigma))+(-cosh(tau)^3+cosh(tau)^2*cos(sigma)+cosh(tau)-cos(sigma))*(diff(diff(r(sigma, tau, phi), tau), tau))+(-cosh(tau)+cos(sigma))*(diff(diff(r(sigma, tau, phi), phi), phi))+sinh(tau)*(cosh(tau)*cos(sigma)-1)*(diff(r(sigma, tau, phi), tau))+(cosh(tau)^2*sin(sigma)-sin(sigma))*(diff(r(sigma, tau, phi), sigma))+r(sigma, tau, phi)*(cosh(tau)-cos(sigma)))*sqrt(a^2/(cosh(tau)-cos(sigma))^2)*(cosh(tau)+1)^2*(cosh(tau)-1)^2)/(sqrt(a^2/(cosh(tau)-cos(sigma))^2)*a^2*sinh(tau)^6)})

(2)

simplify(expand(Gradient(V)));

Error, invalid input: VectorCalculus:-Gradient expects its 1st argument, f, to be of type algebraic, but received Vector(3, {(1) = p(sigma, tau, phi), (2) = q(sigma, tau, phi), (3) = r(sigma, tau, phi)}, attributes = [vectorfield, coords = OPToroid[sigma, tau, phi]])

 

LinearAlgebra:-Transpose(Jacobian(V));

Matrix(3, 3, {(1, 1) = diff(p(sigma, tau, phi), sigma), (1, 2) = diff(q(sigma, tau, phi), sigma), (1, 3) = diff(r(sigma, tau, phi), sigma), (2, 1) = diff(p(sigma, tau, phi), tau), (2, 2) = diff(q(sigma, tau, phi), tau), (2, 3) = diff(r(sigma, tau, phi), tau), (3, 1) = diff(p(sigma, tau, phi), phi), (3, 2) = diff(q(sigma, tau, phi), phi), (3, 3) = diff(r(sigma, tau, phi), phi)})

(3)

 


 

Download lapl6.mw

 

either of the animations in the attached as "consuming a lot of resources"

  restart;
  with(plots):
  P:=[1,1]:
  Q:=[2,2]:
  pltOpts:=symbol=solidcircle, symbolsize=20, color=red:
  nf:=50:
  animate( pointplot,
           [ (1-i/nf)*~P+(i/nf)*~Q,
             pltOpts,
             title="Point Only"
           ],
           i=0..nf,
           frames=nf
         );
  animate( pointplot,
           [ [ 'seq
                ( (1-j/nf)*~P+(j/nf)*~Q,
                  j=0..i
                )'
             ],
             pltOpts,
             title="Trail"
           ],
           i=0..nf,
           frames=nf
         );

 

 

 

 

Download anims.mw

No problem executing any of your code in Maple 2019 - see the attached.

The output of your command sin(x) is interesting. Since 'x' is undefined, Maple ought to return 'sin(x)'. The only occasions reported here where random numeric values are returned in such a situation, is when an illegal (aka "cracked") version of Maple is being used.

Assuming you haev a "paid for" version of Maple with a valid activation code, I can only suggest that you contact Maple support

plot(sin(x), x = -2*Pi .. 2*Pi);

 

sin(x);

sin(x)

(1)

plot3d(x*exp(-x^2 - y^2), x = -2 .. 2, y = -2 .. 2, color = x);

 

with(GraphTheory):
G := Graph({{a, b}, {a, c}, {b, c}});
DrawGraph(G)

GRAPHLN(undirected, unweighted, [a, b, c], Array(%id = 18446744074371012838), `GRAPHLN/table/4`, 0)

 

 

 


 

Download map2019.mw

 

  1. Carl is correct about the name conflict (fixed in the attached)
  2. Even with this "fix", the numeric solver fails on the first ODE system, because the "initial Newton iteration is not converging". There are several possible causes of this problem, which may be worth investigating, but
  3. The information you require ( ie y(t) ), can be obtained by solving only the first two ODEs in the system with their associated boundary conditions. The other five ODEs in the system (togther with their associated boundary conditions) appear to be "superfluous". This strikes me as odd - why would you define them, if you don't need them??
  4. It is possible that the non-convergence problem and the "superfluous" equations are related in some way, but I think you should carefully consider why your system contains equations you don't seem to need. I'm geussing that either I have got something wrong somewhere - or you have!
  5. So in the attached I have solved a "reduced" version of your first ODE system. It *may* be possible to use the solutions for x(t) and y(t) to solve the other equations in this system (if indeed it is necessary)

Anyway, for what it is worth, the attached shows the solutions

restart:
with(plots):
r := 3: r__1 := 3: k := 10: a := 0.2e-1: b := 0.1e-1:
 c := 0.1e-1: beta := 0.3e-1: alpha := 0.3e-1: m := 0.5e-1:
z := 40: q := 5: p := 100: T := 3:
sigma := 0.1e-1: k__1 := 10: rho := 0.5e-1:

 u[1] := min(max(0, z), 1):
 z := (a*m*k*lambda[2](t)*x(t)*y(t)-lambda[1](t)*r*(1+b*x(t)+c*y(t))*x(t)*x(t))/(z*k*(1+b*x(t)+c*y(t))):
 u[2] := min(max(0, q), 1):
 q := -lambda[1](t)*beta*x(t)*s(t)/q:
 u[3] := min(max(0, p), 1):
 p := -(r__1*lambda[3](t)*s(t)*s(t))/(p*k__1):
 sys := diff(x(t), t) = r*x(t)*(1-(1-u[1])*x(t)/k)-a*m*x(t)*y(t)/(1+b*x(t)+c*y(t))-beta*(1-u[2])*x(t)*s(t),
        diff(y(t), t) = -alpha*y(t)+a*m*x(t)*y(t)/(1+b*x(t)+c*y(t)),
        diff(s(t), t) = sigma*s(t)+r__1*s(t)*(1-(1-u[3])*s(t)/k__1)-rho*s(t)*y(t),
        diff(lambda[1](t), t) = -lambda[1](t)*(r-2*r*(1-u[1])*x(t)/k-a*y(t)*(1+c*y(t))/((1+b*x(t)+c*y(t))*(1+b*x(t)+c*y(t)))-beta*(1-u[2])*s(t))-lambda[2](t)*a*m*(1-u[1])*(1+c*y(t))*y(t)/((1+b*x(t)+c*y(t))*(1+b*x(t)+c*y(t))),
        diff(lambda[2](t), t) = -lambda[1](t)*a*x(t)*(1+b*x(t))/((1+b*x(t)+c*y(t))*(1+b*x(t)+c*y(t)))+lambda[2](t)*(-alpha+(a*m*(1-u[1]) . (1+b*x(t)))*x(t)/((1+b*x(t)+c*y(t))*(1+b*x(t)+c*y(t))))+lambda[3](t)*rho*s(t),
       diff(lambda[3](t), t) = lambda[1](t)*beta*(1-u[2])*x(t)-lambda[1](t)*(r__1-2*r__1*(1-u[3])*s(t)/k__1-sigma-rho*y(t)),
       x(0) = 10, y(0) = 20, s(0) = 10, lambda[1](T) = 0, lambda[2](T) = 0, lambda[3](T) = 0:
#p1 := dsolve({sys}, type = numeric):
  p1:=dsolve([sys[1..2], sys[7..8]], numeric):
  p2o := odeplot( p1,
                  [t, y(t)],
                  0 .. 2,
                  labels = ["Time (months)", " "*`badbiomass""spatina"""`],
                  labeldirections =   [horizontal, vertical],
                  color = red,
                  axes = boxed
                );

 

  r := 3: r__1 := 3: k := 10: a := 0.2e-1: b := 0.1e-1:
  c := 0.1e-1: beta := 0.3e-1: alpha := 0.3e-1: m := 0.5e-1:
  sigma := 0.1e-1: k__1 := 10: rho := 0.5e-1:
  z := 40: q := 5: p := 100: T := 3:
  fun := diff(x(t), t) = r*x(t)*(1-x(t)/k)-a*m*x(t)*y(t)/(1+b*x(t)+c*y(t))-beta*x(t)*s(t),
         diff(y(t), t) = -alpha*y(t)+a*m*x(t)*y(t)/(1+b*x(t)+c*y(t)),
         diff(s(t), t) = sigma*s(t)+r__1*s(t)*(1-s(t)/k__1)-rho*s(t)*y(t),
         x(0) = 10, y(0) = 20, s(0) = 10:
  p2 := dsolve({fun}, type = numeric);
  p2i := odeplot( p2,
                  [t, y(t)],
                  0 .. 2,
                  labels = ["Time(months)", " bad biomass"],
                  labeldirections = [horizontal, vertical],
                  axes = boxed,
                  color = blue
                );
  plots[display](p2i, p2o);

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) = 3, (2) = 3, (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.51496316599999606e-1, (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..3, {(1) = 10.0, (2) = 10.0, (3) = 20.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..3, {(1) = .1, (2) = .1, (3) = .1}, datatype = float[8], order = C_order), Array(1..3, {(1) = .0, (2) = .0, (3) = .0}, datatype = float[8], order = C_order), Array(1..3, {(1) = .0, (2) = .0, (3) = .0}, datatype = float[8], order = C_order), Array(1..3, {(1) = .0, (2) = .0, (3) = .0}, datatype = float[8], order = C_order), Array(1..3, {(1) = .0, (2) = .0, (3) = .0}, datatype = float[8], order = C_order), Array(1..3, 1..3, {(1, 1) = .0, (1, 2) = .0, (1, 3) = .0, (2, 1) = .0, (2, 2) = .0, (2, 3) = .0, (3, 1) = .0, (3, 2) = .0, (3, 3) = .0}, datatype = float[8], order = C_order), Array(1..3, 1..3, {(1, 1) = .0, (1, 2) = .0, (1, 3) = .0, (2, 1) = .0, (2, 2) = .0, (2, 3) = .0, (3, 1) = .0, (3, 2) = .0, (3, 3) = .0}, datatype = float[8], order = C_order), Array(1..3, {(1) = .0, (2) = .0, (3) = .0}, datatype = float[8], order = C_order), Array(1..3, 1..3, {(1, 1) = .0, (1, 2) = .0, (1, 3) = .0, (2, 1) = .0, (2, 2) = .0, (2, 3) = .0, (3, 1) = .0, (3, 2) = .0, (3, 3) = .0}, datatype = float[8], order = C_order), Array(1..3, 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, (3, 1) = .0, (3, 2) = .0, (3, 3) = .0, (3, 4) = .0, (3, 5) = .0, (3, 6) = .0}, datatype = float[8], order = C_order), Array(1..3, {(1) = 0, (2) = 0, (3) = 0}, datatype = integer[8]), Array(1..3, {(1) = .0, (2) = .0, (3) = .0}, datatype = float[8], order = C_order), Array(1..3, {(1) = .0, (2) = .0, (3) = .0}, datatype = float[8], order = C_order), Array(1..3, {(1) = .0, (2) = .0, (3) = .0}, datatype = float[8], order = C_order), Array(1..3, {(1) = .0, (2) = .0, (3) = .0}, datatype = float[8], order = C_order), Array(1..3, {(1) = .0, (2) = .0, (3) = .0}, datatype = float[8], order = C_order), Array(1..6, {(1) = .0, (2) = .0, (3) = .0, (4) = .0, (5) = .0, (6) = .0}, datatype = float[8], order = C_order)]), ( 8 ) = ([Array(1..3, {(1) = 10.0, (2) = 10.0, (3) = 20.0}, datatype = float[8], order = C_order), Array(1..3, {(1) = .0, (2) = .0, (3) = .0}, datatype = float[8], order = C_order), Array(1..3, {(1) = -9.9, (2) = -3.1538461538461537, (3) = -.4461538461538461}, datatype = float[8], order = C_order), 0, 0]), ( 11 ) = (Array(1..6, 0..3, {(1, 1) = .0, (1, 2) = .0, (1, 3) = .0, (2, 0) = .0, (2, 1) = .0, (2, 2) = .0, (2, 3) = .0, (3, 0) = .0, (3, 1) = .0, (3, 2) = .0, (3, 3) = .0, (4, 0) = .0, (4, 1) = .0, (4, 2) = .0, (4, 3) = .0, (5, 0) = .0, (5, 1) = .0, (5, 2) = .0, (5, 3) = .0, (6, 0) = .0, (6, 1) = .0, (6, 2) = .0, (6, 3) = .0}, datatype = float[8], order = C_order)), ( 10 ) = ([proc (N, X, Y, YP) option `[Y[1] = s(t), Y[2] = x(t), Y[3] = y(t)]`; YP[1] := 0.1e-1*Y[1]+3*Y[1]*(1-(1/10)*Y[1])-0.5e-1*Y[1]*Y[3]; YP[2] := 3*Y[2]*(1-(1/10)*Y[2])-0.10e-2*Y[2]*Y[3]/(1+0.1e-1*Y[2]+0.1e-1*Y[3])-0.3e-1*Y[2]*Y[1]; YP[3] := -0.3e-1*Y[3]+0.10e-2*Y[2]*Y[3]/(1+0.1e-1*Y[2]+0.1e-1*Y[3]); 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] = s(t), Y[2] = x(t), Y[3] = y(t)]`; YP[1] := 0.1e-1*Y[1]+3*Y[1]*(1-(1/10)*Y[1])-0.5e-1*Y[1]*Y[3]; YP[2] := 3*Y[2]*(1-(1/10)*Y[2])-0.10e-2*Y[2]*Y[3]/(1+0.1e-1*Y[2]+0.1e-1*Y[3])-0.3e-1*Y[2]*Y[1]; YP[3] := -0.3e-1*Y[3]+0.10e-2*Y[2]*Y[3]/(1+0.1e-1*Y[2]+0.1e-1*Y[3]); 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..3, {(1) = 0., (2) = 10., (3) = 10.}); _vmap := array( 1 .. 3, [( 1 ) = (1), ( 2 ) = (2), ( 3 ) = (3)  ] ); _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); _i := false; if _par <> [] then _i := `dsolve/numeric/process_parameters`(_n, _pars, _par, _y0) end if; if _ini <> [] then _i := `dsolve/numeric/process_initial`(_n-_ne, _ini, _y0, _pars, _vmap) or _i end if; if _i then `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 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]; if type(_EnvDSNumericSaveDigits, 'posint') then _dat[4][26] := _EnvDSNumericSaveDigits else _dat[4][26] := Digits end if; _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, s(t), x(t), y(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

 

 

 

 


 

Download odeProb.mw

want to consider the patmatch() function

You might want to check the explanation in the example worksheet returned by

?Examples/functionaloperators

In particular the distinction between writing 1(x) in 1-D input and 1(x) in 2-D math input - because the first will return '1', and the second will return 'x'

so exhaustive enumeration is feasible. NB this approach would "scale" very badly. There are (almost certainly!) more elegant approaches which would scle better

In the attached I have made a number of assumptions, since your precise conditions are unclear/ambiguous. These are

  1. A>0, B>0, C>0. Allowing any of these to be zero just means changing the start index on the "loops" in the attached
  2. in the requirement that `or`(A,B,C)=2^n, the value n=0 is allowed. Maybe you wnat the minimum value of 'n' to be 1? Again this would be trivial to fix
  3. when you say " A or B can be prime or 2^n  * prime", this is ambiguous. I have interpreted this condition as

         
or(   or(A is prime,   A is 2^n)
       or(B is prime,   B is 2^n )
  )

Since the problem is symmetrical, any permutation of the results obtained would also be a solution

With the above assumptions, check the attached

  restart;

#
# generate list of relevant primes
#
  primList:= [ seq
               ( `if`
                 ( isprime(j),
                   j,
                   NULL
                 ),
                 j=1..60
               )
             ]:
#
# generate list of relevant powers of 2
# NB 2^0 is allowed
#
  powList:= [ seq
              ( 2^j,
                j=0..5
              )
            ]:
#
# generate list of of relevant products
#
  prodList:= select
             ( i-> i<60,
               { seq
                 ( (j*~powList)[],
                   j in primList
                 )
               }
             ):
#
# Generate some relevant logical tests
#
  cond1:= z-> member(z, primList):
  cond2:= z-> member(z, powList):
  cond3:= z-> `or`( cond1(z), cond2(z)):

##########################################
# Check all combinations for Question 1
#
# Initialise solution
#
  sol1:= [a=0, b=0, a+b=0]:
  for i from 1 to 60 do
      for j from 1 to 60-i do
          if   `and`
               ( `or`( cond1(i-j),
                       cond2(i-j)
                     ),
                 `or`( cond3(i),
                       cond3(j)
                     ),
                 `or`( cond1(i),
                       cond1(j)
                     )
               )
          then if   i+j>rhs(sol1[3])
               then sol1:=[a=i,b=j,a+b=i+j];
               fi:
          fi;
       od;
  od;
  sol1;

[a = 31, b = 29, a+b = 60]

(1)

############################################
# Initialize solution
#
  sol2:= [a=0, b=0, c=0, a+b+c=0]:
#
# Check all combinations for Question 2
#
  for i from 1 to 60 do
      for j from 1 to 60-i do
          for k from 1 to 60-j do
              if   `and`
                   ( `or`( cond1(i-j),
                           cond2(i-j)
                         ),
                     `or`( cond1(j-k),
                           cond2(j-k)
                         ),
                     `or`( cond1(i),
                           cond1(j),
                           cond1(k)
                         ),
                     `or`( cond3(i),
                           cond3(j),
                           cond3(k)
                         )
                   )
              then if   i+j+k > rhs(sol2[4])
                   then sol2:= [a=i,b=j,c=k, a+b+c=i+j];
                   fi:
              fi;
          od;
      od;
  od;
  sol2;

[a = 56, b = 3, c = 2, a+b+c = 59]

(2)

 


 

Download logProb.mw

 

This is a classic - so I dug ot some code I wrote many years ago, which is a (reasonably) efficient implementation of the Sieve of Eratosthenes (check Wikipedia for an explanation)

  sieve:= proc( N::integer ) :: list;
                local j, k, prArr:
                                description "The sieve of Eratosthenes":
              #
              # Initialise the array with all even indices
              # >=4 set to zero: other entries set to 1
              #
                prArr:= Array
                        ( 2..N,
                          [ 1,
                            1,
                            seq
                            ( '0,1',
                              j = 2..N/2
                            )
                          ]
                        ):
              #
              # cycle through all odd multiples (other than 1)
              # of all odd indices, setting the entry to 0
              #
                prArr[ [ seq
                                     ( seq
                           ( k*j,
                             j = k..N/k, 2
                           ),
                           k = 3..trunc(sqrt(N)), 2
                         )
                       ]
                     ]:= 0:
              #
              # Return the indices which have non-zero entries
              #
                return [ 2,
                         seq
                         ( `if`
                           ( prArr[j]=0,
                             NULL,
                             j
                           ),
                           j = 3..N, 2
                         )
                       ]:
                    end proc:

sieve(10000);

[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069, 1087, 1091, 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151, 1153, 1163, 1171, 1181, 1187, 1193, 1201, 1213, 1217, 1223, 1229, 1231, 1237, 1249, 1259, 1277, 1279, 1283, 1289, 1291, 1297, 1301, 1303, 1307, 1319, 1321, 1327, 1361, 1367, 1373, 1381, 1399, 1409, 1423, 1427, 1429, 1433, 1439, 1447, 1451, 1453, 1459, 1471, 1481, 1483, 1487, 1489, 1493, 1499, 1511, 1523, 1531, 1543, 1549, 1553, 1559, 1567, 1571, 1579, 1583, 1597, 1601, 1607, 1609, 1613, 1619, 1621, 1627, 1637, 1657, 1663, 1667, 1669, 1693, 1697, 1699, 1709, 1721, 1723, 1733, 1741, 1747, 1753, 1759, 1777, 1783, 1787, 1789, 1801, 1811, 1823, 1831, 1847, 1861, 1867, 1871, 1873, 1877, 1879, 1889, 1901, 1907, 1913, 1931, 1933, 1949, 1951, 1973, 1979, 1987, 1993, 1997, 1999, 2003, 2011, 2017, 2027, 2029, 2039, 2053, 2063, 2069, 2081, 2083, 2087, 2089, 2099, 2111, 2113, 2129, 2131, 2137, 2141, 2143, 2153, 2161, 2179, 2203, 2207, 2213, 2221, 2237, 2239, 2243, 2251, 2267, 2269, 2273, 2281, 2287, 2293, 2297, 2309, 2311, 2333, 2339, 2341, 2347, 2351, 2357, 2371, 2377, 2381, 2383, 2389, 2393, 2399, 2411, 2417, 2423, 2437, 2441, 2447, 2459, 2467, 2473, 2477, 2503, 2521, 2531, 2539, 2543, 2549, 2551, 2557, 2579, 2591, 2593, 2609, 2617, 2621, 2633, 2647, 2657, 2659, 2663, 2671, 2677, 2683, 2687, 2689, 2693, 2699, 2707, 2711, 2713, 2719, 2729, 2731, 2741, 2749, 2753, 2767, 2777, 2789, 2791, 2797, 2801, 2803, 2819, 2833, 2837, 2843, 2851, 2857, 2861, 2879, 2887, 2897, 2903, 2909, 2917, 2927, 2939, 2953, 2957, 2963, 2969, 2971, 2999, 3001, 3011, 3019, 3023, 3037, 3041, 3049, 3061, 3067, 3079, 3083, 3089, 3109, 3119, 3121, 3137, 3163, 3167, 3169, 3181, 3187, 3191, 3203, 3209, 3217, 3221, 3229, 3251, 3253, 3257, 3259, 3271, 3299, 3301, 3307, 3313, 3319, 3323, 3329, 3331, 3343, 3347, 3359, 3361, 3371, 3373, 3389, 3391, 3407, 3413, 3433, 3449, 3457, 3461, 3463, 3467, 3469, 3491, 3499, 3511, 3517, 3527, 3529, 3533, 3539, 3541, 3547, 3557, 3559, 3571, 3581, 3583, 3593, 3607, 3613, 3617, 3623, 3631, 3637, 3643, 3659, 3671, 3673, 3677, 3691, 3697, 3701, 3709, 3719, 3727, 3733, 3739, 3761, 3767, 3769, 3779, 3793, 3797, 3803, 3821, 3823, 3833, 3847, 3851, 3853, 3863, 3877, 3881, 3889, 3907, 3911, 3917, 3919, 3923, 3929, 3931, 3943, 3947, 3967, 3989, 4001, 4003, 4007, 4013, 4019, 4021, 4027, 4049, 4051, 4057, 4073, 4079, 4091, 4093, 4099, 4111, 4127, 4129, 4133, 4139, 4153, 4157, 4159, 4177, 4201, 4211, 4217, 4219, 4229, 4231, 4241, 4243, 4253, 4259, 4261, 4271, 4273, 4283, 4289, 4297, 4327, 4337, 4339, 4349, 4357, 4363, 4373, 4391, 4397, 4409, 4421, 4423, 4441, 4447, 4451, 4457, 4463, 4481, 4483, 4493, 4507, 4513, 4517, 4519, 4523, 4547, 4549, 4561, 4567, 4583, 4591, 4597, 4603, 4621, 4637, 4639, 4643, 4649, 4651, 4657, 4663, 4673, 4679, 4691, 4703, 4721, 4723, 4729, 4733, 4751, 4759, 4783, 4787, 4789, 4793, 4799, 4801, 4813, 4817, 4831, 4861, 4871, 4877, 4889, 4903, 4909, 4919, 4931, 4933, 4937, 4943, 4951, 4957, 4967, 4969, 4973, 4987, 4993, 4999, 5003, 5009, 5011, 5021, 5023, 5039, 5051, 5059, 5077, 5081, 5087, 5099, 5101, 5107, 5113, 5119, 5147, 5153, 5167, 5171, 5179, 5189, 5197, 5209, 5227, 5231, 5233, 5237, 5261, 5273, 5279, 5281, 5297, 5303, 5309, 5323, 5333, 5347, 5351, 5381, 5387, 5393, 5399, 5407, 5413, 5417, 5419, 5431, 5437, 5441, 5443, 5449, 5471, 5477, 5479, 5483, 5501, 5503, 5507, 5519, 5521, 5527, 5531, 5557, 5563, 5569, 5573, 5581, 5591, 5623, 5639, 5641, 5647, 5651, 5653, 5657, 5659, 5669, 5683, 5689, 5693, 5701, 5711, 5717, 5737, 5741, 5743, 5749, 5779, 5783, 5791, 5801, 5807, 5813, 5821, 5827, 5839, 5843, 5849, 5851, 5857, 5861, 5867, 5869, 5879, 5881, 5897, 5903, 5923, 5927, 5939, 5953, 5981, 5987, 6007, 6011, 6029, 6037, 6043, 6047, 6053, 6067, 6073, 6079, 6089, 6091, 6101, 6113, 6121, 6131, 6133, 6143, 6151, 6163, 6173, 6197, 6199, 6203, 6211, 6217, 6221, 6229, 6247, 6257, 6263, 6269, 6271, 6277, 6287, 6299, 6301, 6311, 6317, 6323, 6329, 6337, 6343, 6353, 6359, 6361, 6367, 6373, 6379, 6389, 6397, 6421, 6427, 6449, 6451, 6469, 6473, 6481, 6491, 6521, 6529, 6547, 6551, 6553, 6563, 6569, 6571, 6577, 6581, 6599, 6607, 6619, 6637, 6653, 6659, 6661, 6673, 6679, 6689, 6691, 6701, 6703, 6709, 6719, 6733, 6737, 6761, 6763, 6779, 6781, 6791, 6793, 6803, 6823, 6827, 6829, 6833, 6841, 6857, 6863, 6869, 6871, 6883, 6899, 6907, 6911, 6917, 6947, 6949, 6959, 6961, 6967, 6971, 6977, 6983, 6991, 6997, 7001, 7013, 7019, 7027, 7039, 7043, 7057, 7069, 7079, 7103, 7109, 7121, 7127, 7129, 7151, 7159, 7177, 7187, 7193, 7207, 7211, 7213, 7219, 7229, 7237, 7243, 7247, 7253, 7283, 7297, 7307, 7309, 7321, 7331, 7333, 7349, 7351, 7369, 7393, 7411, 7417, 7433, 7451, 7457, 7459, 7477, 7481, 7487, 7489, 7499, 7507, 7517, 7523, 7529, 7537, 7541, 7547, 7549, 7559, 7561, 7573, 7577, 7583, 7589, 7591, 7603, 7607, 7621, 7639, 7643, 7649, 7669, 7673, 7681, 7687, 7691, 7699, 7703, 7717, 7723, 7727, 7741, 7753, 7757, 7759, 7789, 7793, 7817, 7823, 7829, 7841, 7853, 7867, 7873, 7877, 7879, 7883, 7901, 7907, 7919, 7927, 7933, 7937, 7949, 7951, 7963, 7993, 8009, 8011, 8017, 8039, 8053, 8059, 8069, 8081, 8087, 8089, 8093, 8101, 8111, 8117, 8123, 8147, 8161, 8167, 8171, 8179, 8191, 8209, 8219, 8221, 8231, 8233, 8237, 8243, 8263, 8269, 8273, 8287, 8291, 8293, 8297, 8311, 8317, 8329, 8353, 8363, 8369, 8377, 8387, 8389, 8419, 8423, 8429, 8431, 8443, 8447, 8461, 8467, 8501, 8513, 8521, 8527, 8537, 8539, 8543, 8563, 8573, 8581, 8597, 8599, 8609, 8623, 8627, 8629, 8641, 8647, 8663, 8669, 8677, 8681, 8689, 8693, 8699, 8707, 8713, 8719, 8731, 8737, 8741, 8747, 8753, 8761, 8779, 8783, 8803, 8807, 8819, 8821, 8831, 8837, 8839, 8849, 8861, 8863, 8867, 8887, 8893, 8923, 8929, 8933, 8941, 8951, 8963, 8969, 8971, 8999, 9001, 9007, 9011, 9013, 9029, 9041, 9043, 9049, 9059, 9067, 9091, 9103, 9109, 9127, 9133, 9137, 9151, 9157, 9161, 9173, 9181, 9187, 9199, 9203, 9209, 9221, 9227, 9239, 9241, 9257, 9277, 9281, 9283, 9293, 9311, 9319, 9323, 9337, 9341, 9343, 9349, 9371, 9377, 9391, 9397, 9403, 9413, 9419, 9421, 9431, 9433, 9437, 9439, 9461, 9463, 9467, 9473, 9479, 9491, 9497, 9511, 9521, 9533, 9539, 9547, 9551, 9587, 9601, 9613, 9619, 9623, 9629, 9631, 9643, 9649, 9661, 9677, 9679, 9689, 9697, 9719, 9721, 9733, 9739, 9743, 9749, 9767, 9769, 9781, 9787, 9791, 9803, 9811, 9817, 9829, 9833, 9839, 9851, 9857, 9859, 9871, 9883, 9887, 9901, 9907, 9923, 9929, 9931, 9941, 9949, 9967, 9973]

(1)

 


 

Download eratosthenes.mw

use the genfunc() package, as in the attached

  restart;
  with(genfunc):
  p:=[2,3,4,6,8,9,10,12,14,15,16,18];
#
# Produce recurrence relation
#
  rgf_findrecur(6, p, f, j);

[2, 3, 4, 6, 8, 9, 10, 12, 14, 15, 16, 18]

 

f(j) = 2*f(j-1)-2*f(j-2)+2*f(j-3)-f(j-4)

(1)

#
# Check the above recurrence relation by trying
# to regenerate the sequence
#
  g:=k-> if   k=1
         then 2
         elif k=2
         then 3
         elif k=3
         then 4
         elif k=4
         then 6
         else 2*g(k-1)-2*g(k-2)+2*g(k-3)-g(k-4)
         fi;
  [ seq
    ( g(i),
      i=1..numelems(p)
    )
  ];

proc (k) options operator, arrow; if k = 1 then 2 elif k = 2 then 3 elif k = 3 then 4 elif k = 4 then 6 else 2*g(k-1)-2*g(k-2)+2*g(k-3)-g(k-4) end if end proc

 

[2, 3, 4, 6, 8, 9, 10, 12, 14, 15, 16, 18]

(2)

 


 

Download rgf.mw

I'm not sure the attached is 100% valid, but it does get the *same* answer for the maximal distance, which appears to be

sqrt(3)*(sqrt(2)+4)

which is obtained with  a=1, b=2/3, c=1/3 which are close(?) to the values obtained numerically.

Anyhow, FWIW, check out the attached

  restart;
  with(geom3d):
  point(A, [2,0,0]):
  point(B, [0,3,0]):
  point(C, [0,0,6]):
  assume(a<>0):
  interface(showassumed=0):
  v:= [a,b,c]:
  point(DD, [1,1,1]):
  line(l1, [DD, v]):
  d1:=distance(A, l1)+distance(B, l1)+distance(C,l1);
#
# Just to make things easier for the maximize() function
# use the squares of the individual distances
#
  d2:= distance(A, l1)^2+distance(B, l1)^2+distance(C,l1)^2:
#
# and simplify a bit
#
  d2:= simplify(expand(d2));
#
# Get a "symbolic" maximum
#
  sol:= maximize(d2, a=0..1, b=0..1, c=0..1, location);
#
# Evaluate the "actual" distance function with these values
#
  simplify( eval(d1, sol[2,1,1] ), symbolic);
#
# Get a floating point value for the above, for comparison
# with a numerical optimization
#
  evalf(%);
  Optimization:-Maximize(d1, a=0..1, b=0..1, c=0..1);

((b-c)^2+(-a-c)^2+(a+b)^2)^(1/2)/(a^2+b^2+c^2)^(1/2)+((b+2*c)^2+(-a+c)^2+(-2*a-b)^2)^(1/2)/(a^2+b^2+c^2)^(1/2)+((-5*b-c)^2+(5*a+c)^2+(a-b)^2)^(1/2)/(a^2+b^2+c^2)^(1/2)

 

(33*a^2+(4*b+10*c)*a+30*b^2+12*b*c+9*c^2)/(a^2+b^2+c^2)

 

36, {[{a = 1, b = 2/3, c = 1/3}, 36]}

 

3^(1/2)*(2^(1/2)+4)

 

9.377692975

 

[9.37769297305868754, [a = HFloat(0.9601781534495887), b = HFloat(0.6401187689544771), c = HFloat(0.32005938444499066)]]

(1)

 

Download doDistance.mw

First 7 8 9 10 11 12 13 Last Page 9 of 112