acer

32373 Reputation

29 Badges

19 years, 333 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

@serena88 The seq command takes an optional third argument, for the increment, which can be negative.

> j[[seq(i,i=13..4,-1)],1];

                    j[[13, 12, 11, 10, 9, 8, 7, 6, 5, 4], 1]

@serena88 The seq command takes an optional third argument, for the increment, which can be negative.

> j[[seq(i,i=13..4,-1)],1];

                    j[[13, 12, 11, 10, 9, 8, 7, 6, 5, 4], 1]

@Brettski If you lprint that P[0] atomic-identifier name then you'll likely see something like `#msub(mi("P"),mn("0"))`.

And that is a name (because it is wrapped in single-left name quotes). But the Maple Standard GUI knows to display it as a subscripted name.

@Brettski If you lprint that P[0] atomic-identifier name then you'll likely see something like `#msub(mi("P"),mn("0"))`.

And that is a name (because it is wrapped in single-left name quotes). But the Maple Standard GUI knows to display it as a subscripted name.

@Christopher2222 The eventual slowdown in the Standard GUI that you described when animating the globe also occurs in later Maple versions. I believe that it is due (effectively) to some kind of memory leak in the GUI that occurs when displaying many 3D plots/frames, which you might observe using the MS-Windows Task Manager or Unix/Linus `top` utility.

I encourage you (too) to submit an SCR on it. The more such problems are reported the better the chance it might get fixed.

Consider x^3-4*x+2=0 for which the solve command returns three explicit expressions containing I. Hence, some simplification may be necessary before testing for the presence of I.

restart:

p := x^3-4*x+2:
#plot(p, x=-3..3);

S := [solve( p=0, x )]:

remove( has, S, I );

                               []

remove(has, map(simplify,S,constant), I):
evalf(%);

           [1.675130870, -2.214319743, 0.5391888726]

And simplify(...,constant) may not suffice, in general. And `is` will depend upon Digits (akin to fnormal after evalf), so can also be caught out. Applying evalc@Im can turn this into zero-testing.

acer

Consider x^3-4*x+2=0 for which the solve command returns three explicit expressions containing I. Hence, some simplification may be necessary before testing for the presence of I.

restart:

p := x^3-4*x+2:
#plot(p, x=-3..3);

S := [solve( p=0, x )]:

remove( has, S, I );

                               []

remove(has, map(simplify,S,constant), I):
evalf(%);

           [1.675130870, -2.214319743, 0.5391888726]

And simplify(...,constant) may not suffice, in general. And `is` will depend upon Digits (akin to fnormal after evalf), so can also be caught out. Applying evalc@Im can turn this into zero-testing.

acer

@Markiyan Hirnyk I was just querying what you wanted. It's not hard to get it as a sum (of a product of two numbers of combinations, ie. combinat[numbcomb] calls).

N:=(s,k)->add(combinat[numbcomb](s, i)*combinat[numbcomb](i, k-i),i=0..s);

But you want a closed form for that as a symbolic sum? Can it be in terms of calls to GAMMA and hypergeom (...I'm guessing not)?

Is it just this, for n=0,1,2,3,4,...?

 PolynomialTools:-CoefficientList(expand( (1+x+x^2)^n ),x)

So, do you want something in terms of factorials?

acer

@J4James Since eq2 and bc are both sets, pass the DE system to the dsolve command as the argument,

eq2 union bc

rather than as,

{eq2 union bc}

@J4James Since eq2 and bc are both sets, pass the DE system to the dsolve command as the argument,

eq2 union bc

rather than as,

{eq2 union bc}

@Mac Dude Try setting up your links to the saved help-page using Command,package in the hyperlink. So, its hover-over balloon would say, "Help:Command,package".

(It seemed to work ok for me in Maple 15.01, using a link with either Package,command or Package/command. I saved the help page as topic Package/command. Perhaps if you posted the precise `makehelp` incantation that you used to save the page?)

@Mac Dude Try setting up your links to the saved help-page using Command,package in the hyperlink. So, its hover-over balloon would say, "Help:Command,package".

(It seemed to work ok for me in Maple 15.01, using a link with either Package,command or Package/command. I saved the help page as topic Package/command. Perhaps if you posted the precise `makehelp` incantation that you used to save the page?)

Which applications (from the Application Center) are these, that you looked at and which run in MapleV but not in modern Maple?

Did you write that they run in the Classic GUI, but not in the Standard GUI?

acer

Hi Axel,

I'm not sure that it is ok to measure the accuracy of the approximant by evaluating it under Digits=18 of radix-10 working precision. The Questioner mentioned using the result as C source.

Please pardon any mistakes, but here is some attempt at accuracy measurement:

 

restart:

H := proc(z) option inline;
 (.466433940928848490e-3+(1.11523043757015811+(-1.72989528300231501
 +(4.49729788979802074+(-.319393610864014770+(.545253820724829192e-2
 -.228858722931549036e-4*z)*z)*z)*z)*z)*z)/(.139930182278641728e-2
 +(3.34513159198135990+(-6.52796503942793992+(15.5613951451798833+
 (-6.34533642326600689+(.374356830875784296+(-.590832471659976894e-2
 +(.235408172559887276e-4+.461516094568396518e-9*z)*z)*z)*z)*z)*z)*z)*z);
end proc:
approx:= proc(x::float) option inline; H(x^2)*x^3+x end proc:
capprox:=Compiler:-Compile(approx):

J := proc(x::float)
  local t1;
  t1 := x^2;
  (.4290978931547805+(-0.2150922379775017e-1+(0.1194845227917730e-4
   +(0.1351777597551553e-6+0.1467942640582486e-8*t1)*t1)*t1)*t1)*t1*x
   /(1.287293679464341+(-.5794451431789617+0.2339492595289925e-1*t1)*t1)
   +x;
end proc:
cJ:=Compiler:-Compile(J):

populate_approx:=proc(V::Vector(datatype=float[8]),
                      N::integer[4])
  local i::integer[4], q::float[8], x::float[8];
  q:=Pi/(4.0*N);
  for i from 1 to N do
     x:=(i-1.0)*q;
     V[i]:=approx(x);
  end do:
  NULL:
end proc:
cpopulate_approx:=Compiler:-Compile(populate_approx):

populate_J:=proc(V::Vector(datatype=float[8]),
                 N::integer[4])
  local i::integer[4], q::float[8], x::float[8], t1::float[8];
  q:=Pi/(4.0*N);
  for i from 1 to N do
    x:=(i-1.0)*q;
    t1 := x^2;
    V[i]:=(.4290978931547805+(-0.2150922379775017e-1+(0.1194845227917730e-4
           +(0.1351777597551553e-6+0.1467942640582486e-8*t1)*t1)*t1)*t1)*t1*x
           /(1.287293679464341+(-.5794451431789617+0.2339492595289925e-1*t1)*t1)
           +x;
  end do:
  NULL:
end proc:
cpopulate_J:=Compiler:-Compile(populate_J):

populate_approx_diff:=proc(V::Vector,N::posint)
   local i, q, x;
   q:=evalf(Pi/(4.0*N));
   for i from 1 to N do
      x:=(i-1.0)*q;
      V[i]:=abs(capprox(x)-tan(x));
   end do:
   NULL:
end proc:

populate_J_diff:=proc(V::Vector,N::posint)
   local i, q, x, t1;
   q:=evalf(Pi/(4.0*N));
   for i from 1 to N do
      x:=(i-1.0)*q;
      V[i]:=abs(cJ(x)- tan(x));
   end do:
   NULL:
end proc:

 

We can compute a large number of values, using these candidate replacements of the tangent function. By inlining

the formulae right into procedures that do the calculations inplace on float[8] Vectors we can use Compiler:-Compile

and obtained compiled (from C) programs that run until finished without pausing to call back to Maple.

 

So these next timings illustrate how quickly the function can do (nc=10^7) executions, when compiled from C source.

There is just the initial overhead of making the external call, but no extra overhead per individual execution of the

compiled tangent candidate functions.

 

Unsurprisingly, compiled `J` is faster to populate the double precision array, as it does fewer arithmetic operations

than does compiled `approx`. (Another potential benefit of "smaller" code may be the it's easier to shoehorn into

the limited space on an embedded device.)

 

nc:=10^7:

v1:=Vector[row](nc,datatype=float[8]):
CodeTools:-Usage( cpopulate_approx(v1,nc) );

memory used=0.51KiB, alloc change=0 bytes, cpu time=375.00ms, real time=368.00ms

v2:=Vector[row](nc,datatype=float[8]):
CodeTools:-Usage( cpopulate_J(v2,nc) );

memory used=0.51KiB, alloc change=0 bytes, cpu time=234.00ms, real time=238.00ms

 

Now we wish to compute the absolute errors of our candidate functions.

 

If we compared with the values of tan(x) computed at the same hardware double precision then we would not be taking

into account that values from the double precision builtin `tan` also have some error. We want to compare out candidate

functions against more correct values of tangent, and avoid inadvertantly conjoining any errors in the builtin. Hence we

should raise the working precision when computing the baseline tangent values, and it's also a good idea to do the

subtraction at higher precision. Below, we'll use Digits=30, which ought to suffice.

 

But it's important to note that the candidate replacements for tangent should themselves not be run under higher working

precision, since the end goal is to use then in compiled C, say. The easiest way to get their values is to run Maple's own

Compiler:-Compile against them, which generates something similar to CodeGeneration[C] and then compiles/links to

a shared library that Maple can access via its external calling. All that process is normally hidden, by the Compiler.

 

Digits:=30:

nc:=10^5:

v1diff:=Vector(nc,datatype=float[8]):
populate_approx_diff(v1diff,nc):

v2diff:=Vector(nc,datatype=float[8]):
populate_J_diff(v2diff,nc);

 

We can find the largest absolute error, in both of those collections of values computed. These are very close, about

2.5 ulps each.

 

max(v1diff), max(v2diff);

0.252205478780976976e-15, 0.248056073686935993e-15

 

We can compute the average absolute error, in both of those collections of values computed. Again, they are quite close.

 

[add(t, t in v1diff), add(t, t in v2diff)]/nc: evalf[5](%)[];

0.28429e-16, 0.28208e-16

 

We can also plot the two collections of absolute errors.

 

xpts:=Vector(nc,i->evalhf((i-1.0)*Pi/(4.0*nc)),datatype=float[8]):

plots:-display(Array([
    plot(Matrix([xpts,v1diff],datatype=float[8]),style=point,
         view=0..3e-16,symbolsize=1),
    plot(Matrix([xpts,v2diff],datatype=float[8]),style=point,
         view=0..3e-16,symbolsize=1)
                      ]));

 

Download compiledcompared2.mw

acer

First 396 397 398 399 400 401 402 Last Page 398 of 592