acer

32587 Reputation

29 Badges

20 years, 37 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

Have you seen the relevant section in the Maple 16 version of the Programming Manual? It has several examples.

In the Online Help the pages show it as Chapter 11, but the Online Help's Table of Contents shows it as Chapter 10. It should appear as Chapter 11 in an installed Maple 16 as well. See here, at this date...

Not all packages look the same. Some have a ModuleLoad, some have exports written with option overload, some use a ModuleApply routine, some are loaded from text files, some use $include directives to load in the source of their members, and so on.

If you already have a module with 30 procs then declare those procs you want accessible from outside the module as `exports`, and give the module `option package`. That should allow you to load it using the `with` command.

Then you might want to experiment with saving it to a Library archive (from the session in which you defined it, say). That way you could add that Library location to `libname` in other sessions, and utilize your new package without having to reload it.

acer

To get literal subscripts (aka subliterals) to be preserved upon copy & paste (and not be transformed accidentally into indexed names) try changing the Typesetting level from standard to extended.

You should be able to accomplish that by using the main menubar, Tools->Options-Display->Typesetting level. Or you could accomplish it by issuing the command,

     interface(typesetting='extended'):

acer

Some ideas...

current_marks := [
    [ "Student A", [83,61,75] ],
    [ "Student B",[77,96,64] ],
    [ "Student C", [83,87,85] ]
]:

map( t->[op(1,t),`+`(op(op(2,t)))/nops(op(2,t))], current_marks );

      [["Student A", 73], ["Student B", 79], ["Student C", 85]]

[ seq( [op(1,t),`+`(op(op(2,t)))/nops(op(2,t))], t in current_marks ) ];

      [["Student A", 73], ["Student B", 79], ["Student C", 85]]

[ seq( [t[1],`+`(t[2][])/nops(t[2])], t in current_marks ) ];

      [["Student A", 73], ["Student B", 79], ["Student C", 85]]

calcAvg := a -> (a[1]+a[2]+a[3])/3:

[ seq( [t[1],calcAvg(t[2])], t in current_marks ) ];

      [["Student A", 73], ["Student B", 79], ["Student C", 85]]

map( t->[t[1],calcAvg(t[2])], current_marks );

      [["Student A", 73], ["Student B", 79], ["Student C", 85]]

acer

My understanding is that the Ndynamics package was originally written for MapleV R4 and R5, and that one or more of the authors updated it for Maple 14.

The brief overview here doesn't make the original MapleV version sound like much more than a (likely slower) mechanism for doing what is possible with the external-calling mechanism introduced in Maple 6.

A more detailed description writes that it contains a compiled (from C) 5th order Runge-Kutta scheme for first order ODEs.

The original version may be available here. I have not seen any downloadable link for the version rewritten for Maple 14 (cited here, say).

The Ndynamics' package's box-counting method for estimating the fractal dimension sounds interesting and possibly useful.

But it not so clear that the Ndynamics' package's R-K 5th order compiled solver would do that much better than modern stock maple might do. (Maybe the case of wanting many trajectories computed and stored together, for fast plotting, is an exception?!) There is a Maple->C compilation mechanism already buried within the dsolve/numeric of Maple, for several releases. I would expect that the compiling action done in modern Maple's dsolve/numeric is already faster that earlier attempts to speed up numerical IVP solving (eg. here).

acer

It is a 3rd party package, and is not distributed by Maplesoft with the Maple product.

To use it you would have to get it, and then run Maple and augment `libname` with its location on your filesystem.

acer

restart:

solprocs:=dsolve({diff(x(t),t)=x(t)/diff(z(t),t),
                  diff(x(t),t)=y(t)^3-z(t), diff(y(t),t)=z(t)^4-y(t)^3,
                  x(0)=5,y(0)=4,z(0)=1},numeric,
                  output=listprocedure):

X:=eval(x(t),solprocs):
Y:=eval(y(t),solprocs):
Z:=eval(z(t),solprocs):

plots:-spacecurve([X,Y,Z,0..1],axes=box,labels=[x,y,z]);

acer

Pretend that you don't know about the `unapply` command, because you didn't need it here and the overuse of it so often just leads to more confusion. You really don't need to take an expression, unapply it w.r.t some name(s), and then just use it to make a function call using the same names.

I made a correction in one of the formulas, where you used square-brackets mistakenly, instead of round brackets as a delimiter. (Square brackets are a list data structure constructor.)

You can instantiate those particular numeric values into the parameters in `E2`, to get an expression in terms of only name `t` for plotting, using the `eval` command.

restart;
x := A*exp(-b*t/(2*m))*cos(`ϖ`*t+phi)
     +Fmax*cos(psi*t-theta)/sqrt((k-m*psi)^2+b^2*psi^2);

v := diff(x, t);

E := (1/2)*m*v^2+(1/2)*k*x^2;

E2 := subs(phi = arctan(-vo/(xo*omega)),
           theta = arccos((omega^2-psi^2)/sqrt((omega^2-psi^2)^2+b^2*psi^2)),
           A = sqrt(xo^2+(vo/omega^2)^2),
           `ϖ` = sqrt(k/m-b^2/(4*m^2)),
           psi = sqrt(k/m-b^2/(2*m^2)),
           omega = sqrt(k/m),
           E);

plot(eval(E2, [xo = 1, vo = 1, m = 3, k = 2, b = 1, Fmax = 5]), t = 0 .. 10);

acer

The method of computing roots as eigenvalues of the companion Matrix can succeed for this example, but the working precision for the computation will need to be raised. (It's not enough to simply approximate the coefficients, up front.)

The following may have something close to 15 decimal digits correct in the approximate roots. Of course, that alone is not necessarily enough to prevent resubstitution of these approximate roots into the polynomial from evaluating to quite large error terms.

One nice apsect is that the conditioning of the eigenvalues may be estimated, which in turn may allow estimation of the number of digits correct in the result.

> interface(rtablesize=85):
> with(LinearAlgebra):

> Digits:=35:
> UseHardwareFloats:=false:

> p:=lhs(eq2):

> CM := LinearAlgebra[CompanionMatrix]( p/lcoeff(p)):
> evals,econds:=CodeTools:-Usage( EigenConditionNumbers(CM,
>                                                       output=[values,
>                                                               conditionvalues]) ):

memory used=3.65GiB, alloc change=263.38MiB, cpu time=22.15s, real time=22.19s

> evalf[15]([evals,econds])[];
                                                 [                   -15]
                                                 [6.83402039058672 10   ]
                                                 [                      ]
                                                 [                   -15]
                                                 [6.83402039058672 10   ]
                                                 [                      ]
                                                 [                   -15]
                                                 [7.23648087055059 10   ]
                                                 [                      ]
                                                 [                   -15]
                                                 [7.23648087055059 10   ]
                                                 [                      ]
                                                 [                   -15]
                                                 [7.72656826537971 10   ]
                                                 [                      ]
   [  -63420.8083660614 + 15882.0443487046 I  ]  [                   -15]
   [                                          ]  [7.72656826537971 10   ]
   [  -63420.8083660614 - 15882.0443487046 I  ]  [                      ]
   [                                          ]  [                   -15]
   [  -48960.8695347883 + 44112.8513993174 I  ]  [7.95913665921196 10   ]
   [                                          ]  [                      ]
   [  -48960.8695347883 - 44112.8513993174 I  ]  [                   -15]
   [                                          ]  [7.95913665921196 10   ]
   [  -23575.6140373479 + 62375.9927364401 I  ]  [                      ]
   [                                          ]  [                   -15]
   [  -23575.6140373479 - 62375.9927364401 I  ]  [7.79550985300480 10   ]
   [                                          ]  [                      ]
   [  6869.51662529581 + 66230.4088645521 I   ]  [                   -15]
   [                                          ]  [7.79550985300480 10   ]
   [  6869.51662529581 - 66230.4088645521 I   ]  [                      ]
   [                                          ]  [                   -15]
   [  35683.3880972422 + 54765.4095045969 I   ]  [7.39018130172291 10   ]
   [                                          ]  [                      ]
   [  35683.3880972422 - 54765.4095045969 I   ]  [                   -15]
   [                                          ]  [7.39018130172291 10   ]
   [  56262.7032770921 + 30858.5968377536 I   ]  [                      ]
   [                                          ]  [                   -15]
   [  56262.7032770921 - 30858.5968377536 I   ]  [7.16458832027842 10   ]
   [                                          ]  [                      ]
   [         63712.2874905596 + 0. I          ]  [                   -12]
   [                                          ]  [2.64046687161766 10   ]
   [  -4490.81487200127 + 14039.7304635596 I  ]  [                      ]
   [                                          ]  [                   -12]
   [  -4490.81487200127 - 14039.7304635596 I  ]  [2.64046687161766 10   ]
   [                                          ]  [                      ]
   [  4661.77528188768 + 14090.9460209770 I   ]  [                   -12]
   [                                          ]  [2.42414157635414 10   ]
   [  4661.77528188768 - 14090.9460209770 I   ]  [                      ]
   [                                          ]  [                   -12]
   [  -2121.65249947960 + 7349.05555975920 I  ]  [2.42414157635414 10   ]
   [                                          ]  [                      ]
   [  -2121.65249947960 - 7349.05555975920 I  ]  [                    -7]
   [                                          ]  [ 7.86536504649330 10  ]
   [  -4312.16891175340 + 5528.97534778572 I  ]  [                      ]
   [                                          ]  [                    -7]
   [  -4312.16891175340 - 5528.97534778572 I  ]  [ 7.86536504649330 10  ]
   [                                          ]  [                      ]
   [  -5599.87774260448 + 3411.56735959442 I  ]  [0.00000548793613646838]
   [                                          ]  [                      ]
   [  -5599.87774260448 - 3411.56735959442 I  ]  [0.00000548793613646838]
   [                                          ]  [                      ]
   [  -6096.56267895552 + 1144.72879488528 I  ]  [ 0.0000222204794694478]
   [                                          ]  [                      ]
   [  -6096.56267895552 - 1144.72879488528 I  ]  [ 0.0000222204794694478]
   [                                          ]  [                      ]
   [  1945.43010563903 + 7389.81692110602 I   ]  [ 0.0000649974273786813]
   [                                          ]  [                      ]
   [  1945.43010563903 - 7389.81692110602 I   ]  [ 0.0000649974273786813]
   [                                          ]  [                      ]
   [         -3728.35762624427 + 0. I         ]  [                    -7]
   [                                          ]  [ 8.69409187678178 10  ]
   [  4163.32963691448 + 5525.21035158708 I   ]  [                      ]
   [                                          ]  [                    -7]
   [  4163.32963691448 - 5525.21035158708 I   ]  [ 8.69409187678178 10  ]
   [                                          ]  [                      ]
   [  -666.034693824738 + 89.0743608884305 I  ]  [     0.164147409084180]
   [                                          ]  [                      ]
   [  -666.034693824738 - 89.0743608884305 I  ]  [0.00000908507305552621]
   [                                          ]  [                      ]
   [         -443.570256496263 + 0. I         ]  [0.00000908507305552621]
   [                                          ]  [                      ]
   [         -313.515298592929 + 0. I         ]  [    0.0113538808347120]
   [                                          ]  [                      ]
   [  -227.583703496730 + 101.661379347196 I  ]  [    0.0113538808347120]
   [                                          ]  [                      ]
   [  -227.583703496730 - 101.661379347196 I  ]  [    0.0105982253418562]
   [                                          ]  [                      ]
   [         -193.574903517600 + 0. I         ]  [    0.0265900071306592]
   [                                          ]  [                      ]
   [  -145.481050645228 + 161.838737383739 I  ]  [    0.0664299947640745]
   [                                          ]  [                      ]
   [  -145.481050645228 - 161.838737383739 I  ]  [    0.0664299947640745]
   [                                          ]  [                      ]
   [  -162.417537240137 + 92.5028286999766 I  ]  [    0.0967239843711161]
   [                                          ]  [                      ]
   [  -162.417537240137 - 92.5028286999766 I  ]  [    0.0466591043161048]
   [                                          ]  [                      ]
   [  -70.9152426367036 + 196.010534893725 I  ]  [    0.0466591043161048]
   [                                          ]  [                      ]
   [  -70.9152426367036 - 196.010534893725 I  ]  [    0.0791543596078501]
   [                                          ], [                      ]
   [  -91.8467056238840 + 137.516256190746 I  ]  [    0.0791543596078501]
   [                                          ]  [                      ]
   [  -91.8467056238840 - 137.516256190746 I  ]  [    0.0335043333017338]
   [                                          ]  [                      ]
   [  -4.20192849774382 + 201.126931808762 I  ]  [    0.0335043333017338]
   [                                          ]  [                      ]
   [  -4.20192849774382 - 201.126931808762 I  ]  [    0.0737396950177119]
   [                                          ]  [                      ]
   [  -26.2327116671091 + 137.574850072531 I  ]  [    0.0737396950177119]
   [                                          ]  [                      ]
   [  -26.2327116671091 - 137.574850072531 I  ]  [    0.0278423688347353]
   [                                          ]  [                      ]
   [0.0000305478745502723 + 42.2829210364587 I]  [    0.0278423688347353]
   [                                          ]  [                      ]
   [0.0000305478745502723 - 42.2829210364587 I]  [    0.0359437233240501]
   [                                          ]  [                      ]
   [ 0.0332981130986678 + 93.4490347797405 I  ]  [    0.0359437233240501]
   [                                          ]  [                      ]
   [ 0.0332981130986678 - 93.4490347797405 I  ]  [     0.142583313822050]
   [                                          ]  [                      ]
   [  61.5762026789800 + 194.060587349858 I   ]  [     0.142583313822050]
   [                                          ]  [                      ]
   [  61.5762026789800 - 194.060587349858 I   ]  [    0.0289000136731549]
   [                                          ]  [                      ]
   [  35.5149158680390 + 138.169085576076 I   ]  [    0.0289000136731549]
   [                                          ]  [                      ]
   [  35.5149158680390 - 138.169085576076 I   ]  [    0.0285266322516678]
   [                                          ]  [                      ]
   [  112.556204148170 + 139.833739575300 I   ]  [    0.0285266322516678]
   [                                          ]  [                      ]
   [  112.556204148170 - 139.833739575300 I   ]  [    0.0410078776843704]
   [                                          ]  [                      ]
   [  135.492863023348 + 164.995664877630 I   ]  [    0.0410078776843704]
   [                                          ]  [                      ]
   [  135.492863023348 - 164.995664877630 I   ]  [    0.0336329618299009]
   [                                          ]  [                      ]
   [  192.934825895798 + 116.884896438132 I   ]  [    0.0336329618299009]
   [                                          ]  [                      ]
   [  192.934825895798 - 116.884896438132 I   ]  [    0.0218759469555633]
   [                                          ]  [                      ]
   [  218.043380869584 + 81.9176563034177 I   ]  [    0.0218759469555633]
   [                                          ]  [                      ]
   [  218.043380869584 - 81.9176563034177 I   ]  [    0.0196315696779876]
   [                                          ]  [                      ]
   [  259.481918675673 + 27.0374313762841 I   ]  [    0.0196315696779876]
   [                                          ]  [                      ]
   [  259.481918675673 - 27.0374313762841 I   ]  [    0.0143073301243505]
   [                                          ]  [                      ]
   [  525.139920203801 + 149.195028655021 I   ]  [    0.0143073301243505]
   [                                          ]  [                      ]
   [  525.139920203801 - 149.195028655021 I   ]  [   0.00806392428681448]
   [                                          ]  [                      ]
   [         366.428082821285 + 0. I          ]  [   0.00806392428681448]
   [                                          ]  [                      ]
   [         2220.10187538932 + 0. I          ]  [    0.0161282635360182]
   [                                          ]  [                      ]
   [  5480.42117530095 + 3386.43927933407 I   ]  [    0.0161282635360182]
   [                                          ]  [                      ]
   [  5480.42117530095 - 3386.43927933407 I   ]  [   0.00438744192634571]
   [                                          ]  [                      ]
   [  6025.96540331908 + 1122.46684283300 I   ]  [     0.134638326976213]
   [                                          ]  [                      ]
   [  6025.96540331908 - 1122.46684283300 I   ]  [ 0.0000456644123161654]
   [                                          ]  [                      ]
   [  -11495.4379200716 + 11680.7374888816 I  ]  [ 0.0000456644123161654]
   [                                          ]  [                      ]
   [  -11495.4379200716 - 11680.7374888816 I  ]  [  0.000139799367119212]
   [                                          ]  [                      ]
   [  11631.1850038809 + 11714.9274223953 I   ]  [  0.000139799367119212]
   [                                          ]  [                      ]
   [  11631.1850038809 - 11714.9274223953 I   ]  [                   -13]
   [                                          ]  [5.88439121163392 10   ]
   [         18151.8866586339 + 0. I          ]  [                      ]
   [                                          ]  [                   -13]
   [  16421.5266912582 + 6543.78425611958 I   ]  [5.88439121163392 10   ]
   [                                          ]  [                      ]
   [  16421.5266912582 - 6543.78425611958 I   ]  [                   -13]
   [                                          ]  [5.33907616762245 10   ]
   [  -16302.4370849289 + 6524.28068780812 I  ]  [                      ]
   [                                          ]  [                   -13]
   [  -16302.4370849289 - 6524.28068780812 I  ]  [5.33907616762245 10   ]
   [                                          ]  [                      ]
   [         -18038.8915232836 + 0. I         ]  [                   -13]
                                                 [1.34423468332921 10   ]
                                                 [                      ]
                                                 [                   -13]
                                                 [1.95829860639862 10   ]
                                                 [                      ]
                                                 [                   -13]
                                                 [1.95829860639862 10   ]
                                                 [                      ]
                                                 [                   -13]
                                                 [2.14023156315710 10   ]
                                                 [                      ]
                                                 [                   -13]
                                                 [2.14023156315710 10   ]
                                                 [                      ]
                                                 [                   -13]
                                                 [1.46030692734225 10   ]

acer

Do you mean a reduction something like this?

simplify(F, {omega^(N/2)=-1});

For example,

restart; 

N:=6:

F:=Matrix(N,N,(i,j)->omega^((i-1)*(j-1)));

                 [1    1        1        1        1        1   ]
                 [                                             ]
                 [                2        3        4        5 ]
                 [1  omega   omega    omega    omega    omega  ]
                 [                                             ]
                 [        2       4        6        8        10]
                 [1  omega   omega    omega    omega    omega  ]
                 [                                             ]
            F := [        3       6        9        12       15]
                 [1  omega   omega    omega    omega    omega  ]
                 [                                             ]
                 [        4       8        12       16       20]
                 [1  omega   omega    omega    omega    omega  ]
                 [                                             ]
                 [        5       10       15       20       25]
                 [1  omega   omega    omega    omega    omega  ]

simplify(F,{omega^(N/2)=-1});

                  [1     1       1     1     1        1   ]
                  [                                       ]
                  [                 2                    2]
                  [1   omega   omega   -1  -omega  -omega ]
                  [                                       ]
                  [        2                    2         ]
                  [1  omega    -omega  1   omega   -omega ]
                  [                                       ]
                  [1    -1       1     -1    1       -1   ]
                  [                                       ]
                  [                 2                   2 ]
                  [1  -omega   omega   1   -omega  omega  ]
                  [                                       ]
                  [         2                   2         ]
                  [1  -omega   -omega  -1  omega    omega ]

acer

You probably want the second variant below,

restart:
# Understood, you don't want this for reasons made in the parent post
# from which this was branched.
for i from 1 to 10 do
   evalf(Int(y^i, y=-1/2 .. 1/2));
end do;

                                     0.
                                0.08333333333
                                     0.
                                0.01250000000
                                     0.
                               0.002232142857
                                     0.
                               0.0004340277778
                                     0.
                              0.00008877840909

restart:
for i from 1 to 10 do
   evalf(Int(unapply(y^i,y), -1/2 .. 1/2));
end do;

                                     0.
                                0.08333333333
                                     0.
                                0.01250000000
                                     0.
                               0.002232142857
                                     0.
                               0.0004340277778
                                     0.
                              0.00008877840909

restart:
# Now lexical scoping makes the operator y->i be non-evalhf'able
# and so the Nag method fails and it falls bad to another method
# with slightly different roundoff.
proc() local i;
for i from 1 to 10 do
   print(evalf(Int(y->y^i, -1/2 .. 1/2)));
end do;
end proc();

                                            -15
                              1.788630825 10   
                                0.08333333333
                                     0.
                                0.01250000000
                                            -17
                             -9.886887271 10   
                               0.002232142857
                                     0.
                               0.0004340277778
                                            -18
                             -6.604740566 10   
                              0.00008877840909

restart:
# A strange version of expression form, using an unevaluated function call.
for i from 1 to 10 do
   evalf(Int('proc(Y,ii) Y^ii; end proc'(y,i), y=-1/2 .. 1/2));
end do;

                                     0.
                                0.08333333333
                                     0.
                                0.01250000000
                                     0.
                               0.002232142857
                                     0.
                               0.0004340277778
                                     0.
                              0.00008877840909

acer

detV := proc(A::list) local i, j;
            `*`( seq( seq( A[j]-A[i], i=1..j-1), j=1..nops(A)) );
        end proc:

acer

If your Matrix K has real floating-point entries (or real numeric entries and you don't mind applying evalf to it and get real floats) then you could try it instead as,

   Eigenvectors( Matrix(Transpose(K).K, shape=symmetric) );

which should produce purely real eigenvalues, nicely sorted the same way each instance, without small imainary artefacts (due to roundoff).

acer

Do either of these do better? They both ran in under a second for me in Maple 16.01 using the commandline interface of both 64bit OpenSuSE 10.03 and Windows 7. (Your original form in file int41f went away for a long time for me too, on that Linux.)

restart:

CodeTools:-Usage(

  1/(8.397626817*evalf(Int(abs((-52041.81461+60912.87029*I)
      *conjugate(BesselI(8.397626817*I, 1.941747573*Pi*(1+.5150000000*y)))
      +(52041.81461+60912.87029*I)
      *BesselI(8.397626817*I, 1.941747573*Pi*(1+.5150000000*y)))^2*(.515+y),
                        y = -1/2 .. 1/2,method=_d01ajc)))^(1/2)

                  );

restart:

CodeTools:-Usage(

   1/(8.397626817*evalf(Int(y->abs((-52041.81461+60912.87029*I)
      *conjugate(BesselI(8.397626817*I, 1.941747573*Pi*(1+.5150000000*y)))
      +(52041.81461+60912.87029*I)
      *BesselI(8.397626817*I, 1.941747573*Pi*(1+.5150000000*y)))^2*(.515+y),
                            -1/2 .. 1/2)))^(1/2)

                  );

By forcing that method, or by using operator-form for the integrand, some costly preliminary subtask is avoided. (It could be either expanding the Bessel, or checking for discontinuities, when getting expression-form and an unspecified method -- I didn't investigate which might be the case here...)

As for why it "went away" in one interface and not the other, well, I suspect a session-dependent ordering issue where on;y one of them got lucky. (Terms in a SUM dag might be ordered and accessed differently, according to memory address. That's a guess.)

acer

restart:

P:=sum(cadj[i]*vfinal[i], i = c .. d)-(sum(cadj[i]*vinit[i], i = c .. d)):

factor(combine(P));

               d                                  
             -----                                
              \                                   
               )                                  
              /    cadj[i] (-vinit[i] + vfinal[i])
             -----                                
             i = c                                

acer

You cannot use an indexed name as the parameter of a procedure. The parameter name has to be also of type symbol.

There are two kinds of subscripted name, an indexed name and a subliteral (which is an atomic identifier). The latter of those two can be of type symbol, but the former is only of type name and is not of type symbol.

The easy way to get that, in 2D Math entry mode, is to type it using Ctl-Shift-minus instead of Ctl-minus to get the underscore between the base name and the subscript. Eg. the key strokes   c Ctl-Shift-minus A  instead of c Ctl-minus A

You'll have to be careful to enter them the same way, consistently, wherever they are used in the procedure body.


restart:

f := proc (`#msub(mi("c"),mi("A"))`, `#msub(mi("c"),mi("B"))`) options operator, arrow; `#msub(mi("c"),mi("A"))`+`#msub(mi("c"),mi("B"))` end proc

proc (`#msub(mi("c"),mi("A"))`, `#msub(mi("c"),mi("B"))`) options operator, arrow; `#msub(mi("c"),mi("A"))`+`#msub(mi("c"),mi("B"))` end proc

f(x,y);

x+y

lprint(eval(f));

proc (`#msub(mi("c"),mi("A"))`, `#msub(mi("c"),mi("B"))`) options operator, arrow; `#msub(mi("c"),mi("A"))`+`#msub(mi("c"),mi("B"))` end proc

 


Download subliterals.mw

acer

First 262 263 264 265 266 267 268 Last Page 264 of 338