acer

32717 Reputation

29 Badges

20 years, 84 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

@jaypantone Do you see the same buffered/delayed effect for userinfo statements? (Those have the nice feature that you can turn them all on or off with a single command, and also control different levels of detail. They ought to display in a visually similar way in CLI and Std GUI)

Eg,

p := proc()
  userinfo( 1, p, `This is a userinfo statement`);
  userinfo( 3, p, `This is a level 3 a userinfo statement`);
  userinfo( 1, p, nprintf("This is a level %a userinfo statement,\nconstructed with nprintf", 1));
end proc:

p();

infolevel[p]:=3:
p();

infolevel[p]:=1:
p();

It's interesting that you don't see the delay problem with the `print` command. Here's a thought: does using `print` or `lprint` to print a single character string such as " ", interleaved with your delay-buffered `printf` statements, help at all?

Is this the kind of thing you want?

restart:

x:=[1992,1994,1996,1998,2000,2002,2004]:
y:=[325,310,266,217,178,159,161]:

Statistics[ColumnGraph](y,captions=[seq(sprintf("%a\n\n",_n),_n=x)]);

kernelopts(version);

          Maple 12.02, X86 64 WINDOWS, Dec 10 2008 Build ID 377066

acer

f := 5*A^4*B^3*C^7   +   3*A^2*B^1*C^7  +  31*A^3*B^6*C^11;

                          3  6  11      4  3  7      2    7
                 f := 31 A  B  C   + 5 A  B  C  + 3 A  B C 

Exponents := proc(p,x)
  local F;
  if p::`+` then
    [seq(degree(F,x), F in p)];
  else
    [degree(p,x)];
  end if;
end proc:

Exponents(f, A);
                                  [3, 4, 2]

Exponents(f, B);
                                  [6, 3, 1]

Exponents(f, C);
                                 [11, 7, 7]

Exponents(31*A^3*B^6*C^11, C);
                                    [11]

acer

If you want to call the LinearAlgebra package's commands with their short form names then at the start of your procedures include the statement,

uses LinearAlgebra;

For example,

f := proc(A)
  local res;
  uses LinearAlgebra;
  res := Basis(A);
end proc:

f( [<0,1,1>,<1,2,1>,<1,1,0>] );

                                 [[0]  [1]]
                                 [[ ]  [ ]]
                                 [[1], [2]]
                                 [[ ]  [ ]]
                                 [[1]  [1]]

If you are writing a module based package then you can do that within each of its procedures, be they exports or local (to the module) procedures.

Basically the `uses` statement sets up the relevant name bindings within your procedure, somewhat analogously to how `with` works at the top-level. (nb. `with` is not the thing to do, inside a procedure.)

The `uses` facility is documented in the Description section of the help-page for proc (procedure).

acer

restart:

limit((b^(d+1)-1)/((b-1)*b^d), d = infinity) assuming b>1;

                                      b  
                                    -----
                                    b - 1

limit((b^(d+1)-1)/((b-1)*b^d), d = infinity) assuming b<-1;  # hmm

                                  undefined

Q := simplify( (b^(d+1)-1)/((b-1)*b^d) ) assuming b<>1;

                                         (-d)
                                    b - b    
                               Q := ---------
                                      b - 1  

R := limit(Q, d = infinity) assuming b<-1 or b>1;

                                        b  
                                 R := -----
                                      b - 1

limit(Q, d = infinity) assuming b>=0 and b<1;

                                  infinity

limit(Q, d = infinity) assuming b>=-1 and b<0;

                                  undefined

What is going on as b->1 and d->infinity?

acer

Do you mean something like this? I am guessing that you want subscripts rather than underscores, which in your Maple 2015 can be done using a literal double-underscore.

plot( [[0,0]], labels=[Omega/omega__n,a__0(m)] );

If you want that m to be upright and not italic, you could do it as say,

labels=[typeset('Omega/omega__n'), typeset('a__0(`#mn("m")`)')]

acer

Is this the kind of thing you mean?

restart:

N := 50:

e2 := [seq(k*Pi/N, k=-N..N)]:
e3 := evalf(map(sin, e2)):

e4 := CurveFitting:-Spline(e2, e3, x):

PD := proc(p, v)
  local L;
  L:=convert(p, list);
  piecewise(seq([L[2*i-1],diff(L[2*i],v)][], i=1..floor(nops(L)/2)),
                diff(L[-1],v));
end proc:

de4 := PD(e4, x):

plot([e4, de4], x=-Pi..Pi);

 

acer

There is a call in the OpenMaple API for querying the interrupt signal. A lot of dsolve/numeric is in external compiled code, which could make use of that.

acer

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

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

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

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

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

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

@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

First 225 226 227 228 229 230 231 Last Page 227 of 340