acer

9 years, 305 days


These are answers submitted by acer

expressions

July 31 2015 acer 11433

Such a muddle of expressions and procedures.

Let's try it first with just expressions.

restart:
f := 2*t^3+9*t^2-60*t+1;
deq := diff(f,t);
plot(deq, t=-10..10);
isneg := min(deq,0);
plot(isneg, t=-10..10);
eval(isneg, t=0.12017234);

Now let's try it with procedures.

restart:
f := t -> 2*t^3+9*t^2-60*t+1;
deq := D(f);
plot(deq, -10..10);
isneg := x -> min(deq(x),0);
plot(isneg, -10..10);
isneg(0.12017234);

If you're going to muddle up the middle then you'll very likely have to remember what `unapply` does and when it's needed. See your `df` first "problem", where you've confused the formal parameter `t` of your created operator with the global `t` inside the expression `deq`.

restart:

f := proc (t) 2*t^3+9*t^2-60*t+1 end proc:

deq := diff(f(t),t):

df := t->deq;  ## "this is most likely one of my problems."

                          t -> deq

df(6);

                           2            
                        6 t  + 18 t - 60

df := unapply(deq,t);

                                2            
                        t -> 6 t  + 18 t - 60

df(6);
                              264

acer

e04nfa

July 31 2015 acer 11433

I believe that Maple warning is emitted by the routine Optimization:-External:-E04NFA in the case that the integer return code (ifail) from the external NAG function e04nfa is equal to 1.

> kernelopts(version);

           Maple 2015.0, X86 64 LINUX, Feb 17 2015, Build ID 1022128

> showstat((Optimization::External)::E04NFA, 37..41);

(Optimization::External):-E04NFA := proc(x, istate, probtype, n, nclin, a, bl, bu, cvec, h, QPHESS, prmod)
local uselib, Extcall, lda, ldh, lcvec, clambda, liwork, iwork, ifail, lwork, work, obj, iter, iuser, ruser, ax;
       ...
  37   ifail := Extcall(n,nclin,a,lda,bl,bu,cvec,h,ldh,QPHESS,istate,x,'iter','obj',ax,clambda,iwork,liwork,work,lwork,iuser,ruser,op(prmod:-cb));
  38   if ifail = 1 then
  39     if probtype = "LP" then
  40       userinfo(1,'Optimization',`non-unique global minimum found`)
         else
  41       Warnings:-Issue("necessary conditions met but sufficient conditions not satisfied")
         end if
       elif ifail = 2 then
         ...
       elif ifail = 3 then
         ...
       elif ifail = 4 then
         ...
       elif ifail = 5 then
         ...
       elif ifail = 6 then
         ...
       elif ifail = 7 then
         ...
       elif ifail = ('Undefined') then
         ...
       elif ifail = 0 then
         ...
       else
         ...
       end if;
       ...
end proc

For a more detailed explanation of that return code you could look at Section 6 "Error Indicators and Warnings" on this e04nfa documentation page, where it describes IFAIL=1.

acer

outside hardware range

July 31 2015 acer 11433

The value of exp(10^3) is outside the range of double precision floats, which is a retsriction on the plot dirver.

evalhf(DBL_MAX);
                                         307
                    9.9999999000000001 10   

evalhf(log10(ln(DBL_MAX)));
                      2.85076640519378355

evalhf(exp(10^2.8507664051937835));
                                         307
                    9.9999965783395444 10   

evalhf(exp(10^3));
                        Float(infinity)

Some years ago I made a post about some effects of such restrictions (which affects other products as well).

acer

great question

July 28 2015 acer 11433

As an instructor you can set up a private group on the Maple Cloud, and have your students open worksheets Maple or the MaplePlayer directly from that. And one can access such material via a URL with a browser, too.

Historically the Maple Cloud has been Java based. But Maple TA (now v.10) has already been moving to HTML5. And so has MapleNet. (Those two links both mention not needing Java plugins, with some or all of the tech being HTML5.)

And there are bits of it in the source of the MathApps when viewed by browser off of the Maple Cloud via www.maplecloud.com. The post about the MapleCloud Online cited above uses the words, "No plugins. No Java."

acer

Statistics:-Sample

July 28 2015 acer 11433
restart:         

with(Statistics):

X:=RandomVariable(Normal(0,1)):

M:=Matrix(2,3,datatype=float[8]):          
Sample(X,M):                   

M;

       [-1.07242412799827     -0.617091936909790    -0.0254281280423846]
       [                                                               ]
       [-0.329077870547065    0.214466745245291      1.72882128417783  ]

V:=Vector[row](3,datatype=float[8]):
Sample(X,V):            

V;
          [-0.682128392597197, 0.0993787123287771, -2.22695780238860]

This is quite fast.

M:=Matrix(1000,1000,datatype=float[8]):          

CodeTools:-Usage( Sample(X,M) ):       
memory used=8.08KiB, alloc change=0 bytes, cpu time=51.00ms, real time=56.00ms, gc time=0ns

This syntax for inplace population of a float[8] Matrix/Vector has existed since Maple 16. It's also convenient since the Matrix/Vector can be reused and repopulated repeatedly. Prior to that it was still fast to use Sample with an explicit size arument instead of the inplace syntax, and then one could ArrayTools:-Reshape to get a particular container type.

Since Maple 17 the dimensions of a Matrix result can also be supplied (non-in-place syntax) as follows, using the same X from before,

Sample(X, [3,2]);              

                  [-1.07242412799827      0.214466745245291 ]
                  [                                         ]
                  [-0.329077870547065    -0.0254281280423846]
                  [                                         ]
                  [-0.617091936909790     1.72882128417783  ]

whattype(%);
                                    Matrix

On my 64bit Linux on an Intel i5 it is 600 times slower to create a 1000x1000 entry float[8] Matrix using the Sample command in the first way above,

Matrix(1000, RandomTools[Generate](distribution(Normal(10,3)),
                                   makeproc=true),
       datatype=float[8]):

acer

poundforce, or poundal

July 27 2015 acer 11433
convert(1.0, units, poundforce, slug*foot/second^2);

                                     1.0

convert(1.0, units, poundal, pound*foot/second^2);

                                     1.0

convert(1.0, units, poundforce, newton);

                                 4.448221615

convert(1.0, units, poundal, newton);

                                0.1382549544

And if you did not known the name poundal in advance,

convert( newton, system, FPS );

                         125000000000              
                         ------------ Unit(poundal)
                         17281869297


convert( force, system, FPS, dimension=true );

                                Unit(poundal)

acer

detail

July 27 2015 acer 11433

@Markiyan Hirnyk I agree with Carl and Kitonum about the specifics of what's going on in your example.

Given that fsolve does not allow options to control working precision separately from tolerance (for x, or for forward error of g(x)) then if you expect a specific number of correct digits in the result then the problem must be formulated to allow that to happen.

Your originally created piecewise never gets close enough to VP[14]. The piecewise you created has jump dicontinuities and  never gets close enough to VP[14] for any x value to be accepted as a root.

Your original piecewise minus VP[14] never attains a value smaller in absolute value than 1e-7 for any x, unless the expression is evaluated at very low (yes, low) working precision. Eg,

forget(evalf);
evalf[7]( g(0.02612015) - VP[14] );

                                     0.

So Carl and Kitonum are correct in the sense that your originally constructed piecewise does not attain -- closely enough -- some of the VP[i] values for any x value to be taken as a root with say 10 correct digits.

But the problem is that fsolve does not allow one to specify absolute or relative tolerance on x, or a tolerance on f(x). Instead fsolve uses Digits to construct its tolerances internally, and provides no finer control or specification by the user of what close enough means. I believe that it is resonable to object to this narrow behaviour by fsolve; it would be better if tolerances were allowed as separate options, so that acceptance criteria did not just depend on Digits.

With the current way that fsolve accepts a value as being a root, you have two choices: 1) Temporarily increase Digits when forming g, so that acceptable roots exists at your current Digits, or 2) Construct g at your current Digits but note that acceptable roots then exist when the expression is evaluated at low enough Digits.

Note that when you increase Digits just a little, for initially forming the piecewise, the places where problematic jump discontinities cause problems can appear  more relatively severely at x values different than before.

On my 64bit Maple 2015 for Linux a value of Digits=13 for initial construction of the piecewise where the jump discontinuities were insignificant enough that fsolve found 15 roots when Digits=10. On another OS it may be necessary to go higher, for the initial construction to actually have acceptable roots.

I've tried to illustrate some of this below.


restart:

VP := Vector[row](16, {(1) = 10, (2) = 177.9780267, (3) = 355.9560534,
                       (4) = 533.9340801, (5) = 711.9121068, (6) = 889.8901335,
                       (7) = 1067.868160, (8) = 1245.846187, (9) = 1423.824214,
                       (10) = 1601.802240, (11) = 1779.780267, (12) = 1957.758294,
                       (13) = 2135.736320, (14) = 2313.714347, (15) = 2491.692374,
                       (16) = 2669.670400}):

VE := Vector[row](16, {(1) = 5.444193931, (2) = .4793595141, (3) = .3166653569,
                       (4) = .2522053489, (5) = .2123038784, (6) = .1822258228,
                       (7) = .1544240625, (8) = .1277082078, (9) = .1055351619,
                       (10) = 0.8639065510e-1, (11) = 0.6936612570e-1,
                       (12) = 0.5388339810e-1, (13) = 0.3955702170e-1,
                       (14) = 0.2612014630e-1, (15) = 0.1338216460e-1,
                       (16) = 0.1203297900e-2}):

oldDigits,Digits := Digits,10:
#oldDigits,Digits := Digits,13: # this might be adequate to find 15 roots at Digits=10
forget(evalf);
for i to 15 do
  p[i] := VE[i+1] < x and x <= VE[i],
          (VP[i+1]-VP[i])*(x-VE[i])/(VE[i+1]-VE[i])+VP[i] end do:
Digits := oldDigits:
forget(evalf);

g := unapply(piecewise(seq(p[i], i = 1 .. 15)), x):

forget(evalf);
evalf[8]( g(0.026120146) - VP[14] );

                                   0.0001

forget(evalf);
evalf[7]( g(0.02612015) - VP[14] );

                                     0.

for i to 15 do
  forget(evalf);
  print(proc(j) local res;
                res:=fsolve(g(x) = VP[j]);
                if res::numeric then res else j end if;
        end proc(i));
end do;
forget(evalf);

                                 5.444193930
                                0.4793595141
                                0.3166653569
                                      4
                                0.2123038784
                                0.1822258228
                                      7
                                0.1277082078
                                      9
                                0.08639065507
                                     11
                                0.05388339812
                                0.03955702173
                                     14
                                0.01338216464

#eval(g(x);

oldDigits,Digits := Digits,100:
forget(evalf);
plot([VP[14],g(x)], x=0.0261201462..0.0261201464, discont, gridlines=false);
Digits := oldDigits:
forget(evalf);

oldDigits,Digits := Digits,6:
for i to 15 do
  forget(evalf);
  print(proc(j) local res;
                res:=fsolve(g(x) = VP[j]);
                if res::numeric then res else j end if;
        end proc(i)) end do;
Digits := oldDigits:
forget(evalf);

                                   5.44419
                                  0.479360
                                  0.316665
                                  0.252205
                                  0.212304
                                  0.182226
                                  0.154424
                                  0.127708
                                  0.105535
                                  0.0863907
                                  0.0693661
                                  0.0538834
                                  0.0395570
                                  0.0261201
                                  0.0133822

oldDigits,Digits := Digits,12: # still not a good enough construction
forget(evalf);
for i to 15 do
  p[i] := VE[i+1] < x and x <= VE[i],
          (VP[i+1]-VP[i])*(x-VE[i])/(VE[i+1]-VE[i])+VP[i] end do:
Digits := oldDigits:
forget(evalf);

g := unapply(piecewise(seq(p[i], i = 1 .. 15)), x):

for i to 15 do
  forget(evalf);
  print(proc(j) local res;
                res:=fsolve(g(x) = VP[j]);
                if res::numeric then res else j end if;
        end proc(i));
end do;
forget(evalf);

                                 5.444193931
                                0.4793595141
                                0.3166653569
                                0.2522053489
                                0.2123038784
                                0.1822258228
                                0.1544240625
                                0.1277082078
                                0.1055351619
                                0.08639065510
                                     11
                                0.05388339810
                                0.03955702170
                                0.02612014630
                                0.01338216460

oldDigits,Digits := Digits,100:
forget(evalf);
plot([VP[11],g(x)], x=0.69366125699e-1..0.69366125701e-1, discont, gridlines=false);
Digits := oldDigits:
forget(evalf);

oldDigits,Digits := Digits,13: # adequate in 64bit Maple 2015 on Linux
forget(evalf);
for i to 15 do
  p[i] := VE[i+1] < x and x <= VE[i],
          (VP[i+1]-VP[i])*(x-VE[i])/(VE[i+1]-VE[i])+VP[i] end do:
Digits := oldDigits:
forget(evalf);

g := unapply(piecewise(seq(p[i], i = 1 .. 15)), x):

for i to 15 do
  forget(evalf);
  print(proc(j) local res;
                res:=fsolve(g(x) = VP[j]);
                if res::numeric then res else j end if;
        end proc(i));
end do;
forget(evalf);

                                 5.444193931
                                0.4793595141
                                0.3166653569
                                0.2522053489
                                0.2123038784
                                0.1822258228
                                0.1544240625
                                0.1277082078
                                0.1055351619
                                0.08639065510
                                0.06936612570
                                0.05388339810
                                0.03955702170
                                0.02612014630
                                0.01338216460

 


Download fsolveex.mw

I learned a lot by reading closely the solutions and answers given by experts, to questions posted in public forums. For me that included reading everything that Robert Israel and Joe Riel posted on the USENET newsgroup sci.math.symbolic in the early 1990s (and later, in comp.soft-sys.math.maple).

There are also lots of great answers archived on this Mapleprimes forum. You could do a lot worse that start with the Answers posted here by Joe and Robert. Of course there are several other members here who frequently post great answers.

Another thing that I believe has helped some people gain in their advanced understanding of Maple is reading the source code of stock Library routines. Some packages, such as Statistics and Finance, are dense thickets of OO methods. And some other packages have a completely differenct style. Some routines are old, and some are new. Even without comments I find them fascinating to read. Commands that can help in looking at them include showstat, kernelopts(opaquemodules=false), interface(verboseproc=3), and print.

acer

hmm

July 24 2015 acer 11433

In Maple 2015.1 this works (for me) as you expected,

indets(expr, HODD &under (convert, compose, `D`, `global`));

Maybe the next step is poking inside it, while using something like,

indets(expr, HODD &under (proc(q) local orig, res; orig:=convert(q,D); res:=convert(orig,`global`); end proc));

The conversion to `global` might be a red herring. But what is the difference between `orig` and `res` inside that custom procedure? Inside that custom proc both orig and res appear to be of type HODD. Time for hackware... but no time right now for me...

I understand that you know several other ways to get the desired answer. I interpret your question as being about what is going wrong, specifically, when it's done under AddType. On that note I'd first change the dummy name `D` in this to something else, even though it's very likely of no consequence. (One has to start somewhere, before digging into AddType...)

satisfies(D-> nops([op(D)]) > 1)

acer

PDF

July 24 2015 acer 11433

The Programming Manual included in Maple 2015, in PDF format.

The Programming Manual included in Maple 18, in PDF format.

See the Documentation Center for such material.

acer

premature evaluation

July 23 2015 acer 11433

This problem is #8 on Robert Israel's list of Top Ten Maple Errors.

acer

Startup Code

July 22 2015 acer 11433

Look in the Startup Code of a MathApp, to see the definitions of the procedures, modules, etc, accessed by its embedded components.

If you right-click on an embedded component you'll see a popup menu with an item like "Edit Value Changed Action". Selecting that menu items raises a popup editing window with the "action code" of the component. This is the code that gets executed when you move a Slider, press a Button, etc.

Most of the MathApps have very brief "action code", mostly function calls to procedures or modules that are defined elsewhere, in the Startup Code region of the App worksheet.

MathApps are worksheets that are stored in the Help database, rather than in the Library archives. That's not relevant to finding the action code. I just wanted to clarify the wording.

acer

parametric solutions

July 21 2015 acer 11433


restart:

with(RootFinding:-Parametric):

 

  Consider 1/a * (a*x^2 + b*x + c) with B=b/a, C=c/a

 

  (You can also think of this like the special case  a = 1for your original three parameter form.  It makes it easier to visualize, perhaps, with just two parameters.)

f := x^2 + B*x + C;

B*x+x^2+C

DiscriminantVariety([f=0], [x]);

[[B^2-4*C]]

m := CellDecomposition([f=0], [x]):

NumberOfSolutions(m);

[[1, 2], [2, 2], [3, 0], [4, 2]]

 

The last result above means that each point in Cell 1 has 2 roots, each point in Cell 3 has zero roots, etc.

 

CellPlot(m, 'samplepoints');

 

In other words, if  B^2-4*C > 0 then we are inside Cell 1 or 2 or 4 and there are two real roots. I leave to you the easy task of showing that there is just one real root (of multiplicity 2) when  B^2 = 4*C .  And inside Cell 3 there are no roots.

 

So if  C < (1/4)*B^2 then there are two real roots, and if  C = (1/4)*B^2then there is is only one distinct root, and if  C > (1/4)*B^2then there are no real roots.

 

Now let's revisit the form with there parameters a, b, and c.

 

F := a*x^2 + b*x + c;

a*x^2+b*x+c

discrim(F, x);

-4*a*c+b^2

plots:-implicitplot3d( discrim(F, x), a=-1..1, b=-1..1, c=-1..1,
                       grid=[35,35,35], style=patchnogrid, color=blue,
                       orientation=[55,80,-25] );

 

Take any positive value for `a`. In that case there are two real roots of F when  c < b^2/(4*a), one real root when  c = b^2/(4*a), and zero real roots when  c > b^2/(4*a).  And for negative `a` those inequalities are flipped.

 

We can get similar results from the `solve` command.

 

solve( {a*x^2 + b*x + c}, x, real, parametric );

piecewise(And(a = 0, b = 0, c = 0), [[x = x]], And(a = 0, 0 < b), [[x = -c/b]], And(a = 0, b < 0), [[x = -c/b]], And(0 < a, c = b^2/(4*a)), [[x = -(1/2)*b/a]], And(0 < a, c < b^2/(4*a)), [[x = (1/2)*(-b+sqrt(-4*a*c+b^2))/a], [x = -(1/2)*(b+sqrt(-4*a*c+b^2))/a]], And(a < 0, c = b^2/(4*a)), [[x = -(1/2)*b/a]], And(a < 0, b^2/(4*a) < c), [[x = (1/2)*(-b+sqrt(-4*a*c+b^2))/a], [x = -(1/2)*(b+sqrt(-4*a*c+b^2))/a]], [])

 


Download discrim.mw

acer

frontend

July 21 2015 acer 11433

There are some situations where one does not want any expansion (or simplification) to occur other than the simplest arithmetic changes necessary to find a polynomial pattern by algsubs.

In some such cases it can help to frontend the expand call.

In the following example, I'd prefer that the 1-cos(y+v)^2 is left alone, say.


z := -d*(1-cos(y+v)^2+a)+a;

-d*(1-cos(y+v)^2+a)+a

algsubs((a-a*d)=c,expand(z));

(cos(y)^2*cos(v)^2-2*cos(y)*cos(v)*sin(y)*sin(v)+sin(y)^2*sin(v)^2-1)*d+c

simplify(z,{a-a*d=c});

(cos(y)^2*cos(v)^2-2*cos(y)*cos(v)*sin(y)*sin(v)+sin(y)^2*sin(v)^2-1)*d+c

algsubs((a-a*d)=c,frontend(expand,[z]));

(cos(y+v)^2-1)*d+c


Download frontend.mw

acer

assumption on a

July 20 2015 acer 11433
int((a/2)*exp(-a*abs(x)),x=-infinity..infinity) assuming Re(a)>0;

                               1

Or, if a is to be real, then under the assumption that a>0.

acer

1 2 3 4 5 6 7 Last Page 1 of 113