acer

32333 Reputation

29 Badges

19 years, 319 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

Why exactly do you need to display the expanded expression? You wrote, "in order to check its sign". Do you mean that you will be checking it visually, by inspection? Is that the only reason for having its expanded form be printed? Wouldn't it be easier to have have Maple report the sign to you directly, programmatically?

acer

As far as the error goes, see the attached revision of the worksheet.

code_2_corr.mw

It might not be a big portion of the time resources used by your code (esp. at few iterations) but repeatedly concatenating lists with code like,

function1 := [op(function1], ...];

executed in a loop is inefficient and scales worse in resources used as the list length gets high. Perhaps see a response to your other recent question, where results are stored in a table as they are individually computed and then converted to a list of lists altogether -- only when the looping is finished.

Is it really necessary to compute at Digits=20, because that likely incurs quite a performance penalty. If you leave Digits=10, ie, at its default value, then do you get enough accuracy? Are you only needing the results for a final plot -- because you don't need much, much better than about 1e-5 rel. accuracy for that, do you?

acer

Here is a modification of your worksheet, that gets a 3D pointplot.

I made a few modifications to the ranges of the variables, as passed to fsolve. Judging from the piecewise functions it seemed to make sense to bound n1 by -4 from below, so as to not waste time in fsolve's search. It wasn't clear to me whether you wanted to get the points that lay along some single spacecurve (as n1 changed), but since there might be other solutions I restricted beta by -2 from below. And I extended the lower bound of `a` to -20, as it seems to extend the curve nicely.

deflection_domain_tr.mw

By the way, since your computational code that invokes fsolve and checks the result is not inside a procedure then I tested it utilizing eval(sol,1) so that the type-check did not cause a wasted efforst in repeating the fsolve computation in the case that it had failed and returned unevaluated. (See here for explanation.)

acer

If you are asking about coursework then check recently posted Questions before submitting a duplicate.

See here for an earlier, answered version of this question.

acer

If you are asking about coursework then you should search the recently asked Questions, before submitting a duplicate.

See here for a recently answered version of this question.

acer

Terminate your do-loop with end do rather than just do.

acer

You might be able to use RootFinding:-NextZero.

For example,

> restart:

> start_x:=-6:  # have to know this

> f:=x->-(2*x-8)^2+20:             

> firstroot:=RootFinding:-NextZero(f,start_x);
                           firstroot := 1.763932022

> RootFinding:-NextZero(f,firstroot);         
                                  6.236067977

Depending on your particular problem you might need to make use of some additional options to NextZero, eg. the `maxdistance` option.

Note that `f` is a procedure. If you have an expression fexpr then you might need to construct a procedure that evaluates it, eg. f:=unapply(fexpr,x) if it is an expression in x.

Of course I'm assuming that your expression is not just a quadratic, because if it were then you could obtain both roots in one call to fsolve, and take the max of those. But you could still try and use fsolve with its avoid option, if you know that there are only two roots.

> restart:

> f:=x->-(2*x-8)^2+20+erf(1/x):     

> r1:=fsolve('f'(x),x);             
                               r1 := 1.731412561

> r2:=fsolve('f'(x),x,avoid={x=r1});
                               r2 := 6.246058929

> max(r1,r2);
                                  6.246058929

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

First 259 260 261 262 263 264 265 Last Page 261 of 336