acer

32348 Reputation

29 Badges

19 years, 329 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

@mmcdara 

For your point 1), I suppose that the element-wise application of is boils down to this kind of thing, where it matters whether the system allows for the second argument as a property.

is(3.000000, 3);

              true

is(sin(x)^2+cos(x)^2, 1);

              true

is(1, sin(x)^2+cos(x)^2);

Error, (in property/ConvertProperty) sin(x)^2+cos(x)^2 is an invalid property

Regarding you followup point 3), the element-wise multiplication of Arrays with the `.` command has been there since Maple 6, if I'm not mistaken. I have no problem with that syntax, which was available long before the element-wise tilde became available. If anything I'd say that I'm not a huge fan of the coercion from Array to Matrix/Vector as now done by LinearAlgebra commands.

A long time ago (Maple 6 time frame, say) there was a strong distinction between a Matrix as a linear mapping from one vector space to another and an Array as a more general kind of 2-dimensional collection of data.  I wouldn't be surprised if the rationale to allow coercion by LinearAlgebra commands were in part motivated by the wish not to surprise users (eg. Matlab users) coming into Maple. The system seemed more logically consistent to me when it was stricter in this regard. A somewhat related issue occurs for the distinction between row and column Vectors.

As for overload, you can read about it in the Help system. It's only my opinion but... they seem very nice and handy, up to the point that one has to debug them.

@Carl Love The DifferentialGeometry package has commands which change the prompt (as a semaphore of context).

@nm 

I have long advocated that help pages should quote option names and option values as if protectively and robustly coding for the most problematic cases. That includes quoting the global name where it may be necessary, where the global name is referenced using colon-dash. Eg.  ':-foo' .

I have a feeling that it's not done like that in the documentation for fear that it would lead to user confusion. (ie. Maple! So many kinds of quotes!) I hold the opposing view -- that properly, consistently, and defensively coding for the corner cases would lead to better understanding or at least acceptance of the safest practice.

nb. The fact that mint and maplemint may not emit any messages for a particular example procedure does not mean that it will compute as desired, or without error. Being "mint-clean" does not necessarily imply correct or error-free computation.

On a somewhat related note, I also think that help pages should utilize the colon-dash syntax when doing full reference to module-based package members, instead of using indexing.  A help page should reference LinearAlgebra:-Norm instead of the indexed form LinearAlgebra[Norm] , including in its Title and Description, as well as in cross-references in any See Also section. The indexed form is inferior in my opinions because it may need to be referenced safely as LinearAlgebra[':-Norm'] in order to guard against collision with possible local name Norm as well as to guard against collision with name Norm possibly being assigned at the higher level. There is some explanation on the help page with topic colondash .

Inductive reasoning is not a mechanism for mathematical proof, and is not mathematical induction. Something's very wrong if one ever mixes those up together in the same context.

A mathematician should not consider that "..it is sometimes very easy to believe induction is sufficient proof...", where the context qualifies that as inductive generalization or "inductive reasoning". 

@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.

First 252 253 254 255 256 257 258 Last Page 254 of 592