acer

33099 Reputation

29 Badges

20 years, 180 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

@David1 

kernelopts(version)

`Maple 2017.2, X86 64 LINUX, Jul 19 2017, Build ID 1247392`


Mixing floats, exact constants like Pi, symbolic names in an expression can present unexpected difficulties.

In this case solve has difficulty figuring out how to handle this example, containing both floats and exact Pi. In particular the comparison of floating-point approximations of the root with the exact values in the inequality can vary according to the number of correctly rounded digits of that root approximation.

restart

Digits

10

eq1 := -1.71010071662834*cos(x)/(25.00000000*cos(x)^2+25.00000000*sin(x)^2)^(1/2); diff_eq1 := expand(diff(eq1, x))

1.71010071662834*sin(x)/(25.00000000*cos(x)^2+25.00000000*sin(x)^2)^(1/2)

sols := solve({diff_eq1, x > -Pi, x <= Pi}, x, explicit, allsolutions)

{x = 0.}

solve({diff_eq1}, x, allsolutions)

{x = 3.141592654*_Z2}

solve({diff_eq1, x > -3.1, x <= 3.2}, x, explicit, allsolutions)

{x = 0.}, {x = 3.141592654}


You may find it interesting that raising Digits has an effect.  (A bit more on this, at the end.)

restart

Digits := 12

12

eq1 := -1.71010071662834*cos(x)/(25.00000000*cos(x)^2+25.00000000*sin(x)^2)^(1/2); diff_eq1 := expand(diff(eq1, x))

1.71010071662834*sin(x)/(25.00000000*cos(x)^2+25.00000000*sin(x)^2)^(1/2)

sols := solve({diff_eq1, x > -Pi, x <= Pi}, x, explicit, allsolutions)

{x = -3.14159265359}, {x = 0.}, {x = 3.14159265359}


Another way to try and deal with this is to convert the floats in the expression to exact rationals.

restart

Digits

10

eq1 := -1.71010071662834*cos(x)/(25.00000000*cos(x)^2+25.00000000*sin(x)^2)^(1/2); diff_eq1 := expand(diff(eq1, x))

1.71010071662834*sin(x)/(25.00000000*cos(x)^2+25.00000000*sin(x)^2)^(1/2)

ex_diff_eq1 := convert(diff_eq1, rational, exact)

(85505035831417/50000000000000)*sin(x)/(25*cos(x)^2+25*sin(x)^2)^(1/2)

solve({ex_diff_eq1, x > -Pi, x <= Pi}, x, explicit, allsolutions)

{x = 0}, {x = Pi}


Below, we can observe that floating-points approximations of Pi, rounded to d decimal digits, are not all "less than or equal" to Pi.

When solve sees floats in the expression is may generate floating-point results (and internally utilize some extra guard-digits). But the comparison of those floating-point approximations with the exact bounds you supplied (ie. x>-Pi and x<=Pi) can be affected by this.

restart; for d from 10 to 30 do Digits := d; forget(evalf); approx := evalf[d](Pi); res := is(approx <= Pi); lprint(sprintf(" Digits = %d, %s, %a ", d, `if`(res, "true ", "false"), approx)) end do

" Digits = 10, false, 3.141592654 "
" Digits = 11, false, 3.1415926536 "
" Digits = 12, false, 3.14159265359 "
" Digits = 13, false, 3.141592653590 "
" Digits = 14, false, 3.1415926535898 "
" Digits = 15, true , 3.14159265358979 "
" Digits = 16, true , 3.141592653589793 "
" Digits = 17, true , 3.1415926535897932 "
" Digits = 18, false, 3.14159265358979324 "
" Digits = 19, true , 3.141592653589793238 "
" Digits = 20, false, 3.1415926535897932385 "
" Digits = 21, true , 3.14159265358979323846 "
" Digits = 22, false, 3.141592653589793238463 "
" Digits = 23, true , 3.1415926535897932384626 "
" Digits = 24, true , 3.14159265358979323846264 "
" Digits = 25, true , 3.141592653589793238462643 "
" Digits = 26, false, 3.1415926535897932384626434 "
" Digits = 27, true , 3.14159265358979323846264338 "
" Digits = 28, true , 3.141592653589793238462643383 "
" Digits = 29, false, 3.1415926535897932384626433833 "
" Digits = 30, false, 3.14159265358979323846264338328 "

``

 

Download trigoac.mw

@tomleslie The worksheet was already there, a few hours before your last claim that it hadn't been uploaded. All you had to do was look. How hard can that be?

(This is the brusque way you often address people here.)

I should also mention the following mechanism (which I often reach for instead of unapply, because it has some more general uses):

Here, the Maple kernel replaces the formal parameter n (of the procedure) for the name n in the expression, when it forms the procedure body.

I also have the choice to declare local x in the template of the procedure body. That can be valuable. (These procedures bar will otherwise pick up any assigned value of x at the higher level from which bar gets called, typically resulting in a run-time error.)

restart;

expr := 'int(x*sin(n*x),x=0..Pi)':

foo := subs( __dummy = expr,
             proc(n::integer)
               __dummy;
             end proc
           ) assuming n::integer;

proc (n::integer) -(-1)^n*Pi/n end proc

(1)

bar := subs( __dummy = eval(expr,1),
             proc(n::integer)
               local x;
               __dummy;
             end proc
           ) assuming n::integer;

proc (n::integer) local x; int(x*sin(n*x), x = 0 .. Pi) end proc

(2)

foo(3), bar(3);

(1/3)*Pi, (1/3)*Pi

(3)

restart;

foo := subs( __dummy = int(x*sin(n*x),x=0..Pi),
             proc(n::integer)
               __dummy;
             end proc
           ) assuming n::integer;

proc (n::integer) -(-1)^n*Pi/n end proc

(4)

bar := subs( __dummy = 'int(x*sin(n*x),x=0..Pi)',
             proc(n::integer)
               local x;
               __dummy;
             end proc
           ) assuming n::integer;

proc (n::integer) local x; int(x*sin(n*x), x = 0 .. Pi) end proc

(5)

foo(3), bar(3);

(1/3)*Pi, (1/3)*Pi

(6)

 


Download subs_proc.mw

When you lprint the Array it does not show the entries whose value are zero (because that is the default value).

@taro 

restart;

r := theta*z;

lo_theta, hi_theta := 0.0, 2.0;
lo_z , hi_z := 0.0, 1.0;

m, n := 3, 2;

theta*z

 

0., 2.0

 

0., 1.0

 

3, 2

(1)


c := plot3d( r,
             theta = lo_theta .. hi_theta,
             z = lo_z .. hi_z,
             coords = cylindrical, grid = [m, n] ):
A:=op([1,1],c);

A := Vector(4, {(1) = ` 1..3 x 1..2 x 1..3 `*Array, (2) = `Data Type: `*float[8], (3) = `Storage: `*rectangular, (4) = `Order: `*Fortran_order})

(2)

lprint(A);

Array(1 .. 3, 1 .. 2, 1 .. 3, {(1, 2, 3) = HFloat(1.), (2, 2, 1) = HFloat(.540302305868139765), (2, 2, 2) = HFloat(.841470984807896505), (2, 2, 3) = HFloat(1.), (3, 2, 1) = HFloat(-.832293673094284814), (3, 2, 2) = HFloat(1.81859485365136342), (3, 2, 3) = HFloat(1.)}, datatype = float[8])

 

i, j := 2, 2;
x = A[i,j,1];
y = A[i,j,2];
z = A[i,j,3];

2, 2

 

x = HFloat(0.5403023058681398)

 

y = HFloat(0.8414709848078965)

 

z = HFloat(1.0)

(3)

x = eval( r*cos(theta), [theta = lo_theta + (i-1)/(m-1)*(hi_theta - lo_theta),
                         z = lo_z + (j-1)/(n-1)*(hi_z - lo_z)] );

y = eval( r*sin(theta), [theta = lo_theta + (i-1)/(m-1)*(hi_theta - lo_theta),
                         z = lo_z + (j-1)/(n-1)*(hi_z - lo_z)] );

z = eval(z, [theta = lo_theta + (i-1)/(m-1)*(hi_theta - lo_theta),
             z = lo_z + (j-1)/(n-1)*(hi_z - lo_z)] );

x = .5403023059

 

y = .8414709848

 

z = 1.0

(4)

i, j := 3, 2;
x = A[i,j,1];
y = A[i,j,2];
z = A[i,j,3];

3, 2

 

x = HFloat(-0.8322936730942848)

 

y = HFloat(1.8185948536513634)

 

z = HFloat(1.0)

(5)

x = eval( r*cos(theta), [theta = lo_theta + (i-1)/(m-1)*(hi_theta - lo_theta),
                         z = lo_z + (j-1)/(n-1)*(hi_z - lo_z)] );

y = eval( r*sin(theta), [theta = lo_theta + (i-1)/(m-1)*(hi_theta - lo_theta),
                         z = lo_z + (j-1)/(n-1)*(hi_z - lo_z)] );

z = eval(z, [theta = lo_theta + (i-1)/(m-1)*(hi_theta - lo_theta),
             z = lo_z + (j-1)/(n-1)*(hi_z - lo_z)] );

x = -.8322936730

 

y = 1.818594854

 

z = 1.0

(6)

 


Download cyl.mw

@Carl Love Good idea. I think I got confused about the question, and was thinking of function calls instead of stored structures.

You might have a look at these profiling mechanisms.

I'm not sure offhand what special support -- if any -- there might be for records or static methods of objects. I find it mostly useful for profiling my "Library level" interpreted procedure calls/usage. The CodeTools functionality is newer.

https://www.maplesoft.com/support/help/Maple/view.aspx?path=CodeTools/Profiling

https://www.maplesoft.com/support/help/Maple/view.aspx?path=exprofile


 

Do you mean that the Matrix appears as 2D Output, or was it inserted as 2D Input by using the Matrix Palette?

If the problem is with the Matrix as typeset 2D Input then does it work if you hit Enter and then try it on the output?

Why not upload a Worksheet or Document that exhibits the problem?

@vv That's nice. Here are a few more ways to accomplish those things -- and a few comments if I may add them -- using that generated f .

These following operator form calls work as they ought to.

int(f, 0..Pi, numeric);
evalf(Int(f, 0..Pi));
int(f, 0..evalf(Pi));

It's clearly a bug that evalf(Int(f(x), x=0..Pi)) does not work, while something weird like evalf(Int(''f(x)'', x=0..Pi)) does produce the float result.

It's unfortunate that D(f) has not yet been taught to return unevaluated, since the hook from evalf(D(...)) into fdiff is a useful syntax. Hopefully someone will fix that in D.

The first of these ideally would work as just evalf(D(f)(2)) . And the third of these ideally would not need the uneval quotes.

evalf(D(t->f(t))(2));
fdiff(f(x), x=2);
evalf(eval(diff('f'(x), x), x = 2));

Similarly, these would look nicer working with just D(f) instead of D(t->f(t)) .

plot([f, D(t->f(t))], 0 .. 10);
plot([f(x), D(t->f(t))(x)], x = 0 .. 10);

As a side note, these both compute without an error message.

fsolve(f, Pi/2..3*Pi/2);
fsolve(f(x), x=Pi/2..3*Pi/2);

And these first two calls succeed, but unfortunately the third emits an error message.

Optimization:-Maximize(f(x), x=0..Pi);
Optimization:-Maximize(t->f(t), 0..Pi);
Optimization:-Maximize(f, 0..Pi);

I suspect that some of these problematic cases relate to appliable modules more generally, and not just to Interpolation objects.

@AliahNiu The image shows {sin(x)}^(d-2) as part of the integrand, which is not valid syntax since the curly braces denote a set. That should be sin(x)^(d-2) .

Christopher2222, please upload the actual .mw file from which you are trying to retrieve the value associated with the "L1" label.

Then tell us exactly which platform you're using, eg. Windows 7 32bit , or Windows 10 64bit , etc.

@Earl Mapleprimes won't let me download those last two attachments, in your Comment immediately above. Could you try uploading them again, without the ampersand in the file name?

@tomleslie I was going to mention this alternate command yesterday, but found it a bit brittle (and not quick). 

Of 800 files collected from Mapleprimes it failed with some error on about 70.

And in at least three cases it failed with an infinite recursion error, which is not catchable and thus stopped my script outright. Ie. it stopped the loop over all the files. I had to remove those filenames from the list and re-run.

Of course it may well work for all of the OP's files.

@tomleslie Does your approach detect the instance of

  with(plottools)

in that second attachment he gave?

I mean, his attachment as is, last saved in Maple 2016 (and running the detection script in Maple 2016 too, though I doubt that would affect it).

 

If you're inputs are in 1D Maple Notation then grep can work, as others have mentioned. That's because 1D input appears in the XML .mw file in plain text.

But if your worksheet contains 2D Input (in an Execution Group) then such input may not appear in plain text in the .mw file. Rather, it may appear encoded within an Equation element within an Input element in the XML .mw file. For example,

str:="LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYnLUkjbWlHRiQ2I1EhRictRiM2JS1GLDYlUSV3aXRoRicvJSdpdGFsaWNHUSV0cnVlRicvJSxtYXRodmFyaWFudEdRJ2l0YWxpY0YnLUkobWZlbmNlZEdGJDYkLUYjNiQtRiw2JVE0VmFyaWF0aW9uYWxDYWxjdWx1c0YnRjRGNy9GOFEnbm9ybWFsRidGQkZCRisvJStleGVjdXRhYmxlR1EmZmFsc2VGJ0ZC":

op(2,Typesetting:-Parse(op(1,sscanf(StringTools:-Decode(str,base64),"%m")))):

lprint(eval(%,1));
  with(VariationalCalculus)

The above is slightly more complicated because the base64 encoding can differ entirely even if the 2D Input varies just a little. For example, if the 2D Input statement contains extra spaces, or terminates with colon, semicolon, or nothing.

In such a situtation it may be necessary to use a programmatic approach to pull out all such 2D Input pieces and decode, worksheet file by file. Maple could be used for this -- even the walking of the directory tree -- but it would be more work. (There's a possibility that one could programmatically extract all 2D Input from each .mw into separate .mpl plaintext files, perhaps even using a current command. But the set of .mw files is still needed.)

With newer "workbooks" (ie. .maple filename extension) the situation could be very difficult.

First 266 267 268 269 270 271 272 Last Page 268 of 606