pagan

5147 Reputation

23 Badges

17 years, 124 days

 

 

"A map that tried to pin down a sheep trail was just credible,

 but it was an optimistic map that tried to fix a the path made by the wind,

 or a path made across the grass by the shadow of flying birds."

                                                                 - _A Walk through H_, Peter Greenaway

 

MaplePrimes Activity


These are answers submitted by pagan

You could do it with simple syntax, by creating a 2x10 Matrix and then casting that to Array.

Digits:=1000:
S := convert(evalf(Pi), string):

Array(<Array(1..10, [seq(i, i=0..9)]),
       Array(1..10, [seq(StringTools:-CountCharacterOccurrences(S, i), i="0".."9")])>);

# Or, if you already have the two row Arrays

r1:=Array(1..10, [seq(i, i=0..9)]):
r2:=Array(1..10, [seq(StringTools:-CountCharacterOccurrences(S, i), i="0".."9")]):

Array(<r1,r2>);
rtable_dims(%);

# And for either method, you can force the indices as 0-based, not 1-based

Array(0..1,0..9,<r1,r2>);
rtable_dims(%);

If you want it as a 1-based 2-d Array, you might also just keep it as the Matrix <r1,r2> .

Yet another way, given r1 and r2 already at hand, is to assign them into pre-made Array A.

A:=Array(0..1,0..9):
A[0,0..9]:=r1:
A[1,0..9]:=r2:
A;

A:=Array(1..2,1..10):
A[1,1..10]:=r1:
A[2,1..10]:=r2:
A;

And lastly, you could use an initializing operator

Array(0..1,0..9,
      (i,j)->`if`(i=1,j,
                  StringTools:-CountCharacterOccurrences(S, convert(j,string))));

Array(1..2,1..10,
      (i,j)->`if`(i=1,j-1,
                  StringTools:-CountCharacterOccurrences(S, convert(j-1,string))));

You can do it, by both reflecting and forcing the tickmarks.

See here, for another recent thread on that.

It would be a useful thing for which to have a more convenient mechanism. (Perhaps justa new option to plottools:-reflect might be enough.)

You mentioned that you want people to be able to open your file using the "Reader". I take that as meaning the Maple Reader. Please clarify, if that's not what you mean.

If you did mean the Maple Reader, specifically, then it looks like you need to know whether you can author an "mbook". If you meant something more like the Maple Player, then you might want to know how/whether you can author one of its ".mwz" files.

It also might help you to know whether someone else's using the Maple Reader means that they also have to possess a working copy of Maple itself. Ie. whether the Reader requires Maple in order to function. Or you might want to know the same thig, about the Maple Player. (You might be asking and curious because the Mathematica Player is advertised as not requiring the end-user to possess a full working copy of Mathematica.)

See this old Post.

This may be happening in LinearAlgebra:-LA_Main:-Eigenvalues.

showstat(LinearAlgebra:-LA_Main:-Eigenvalues,91);

LinearAlgebra:-LA_Main:-Eigenvalues := proc(A, C, impl, outpt, outopts)
local cm, cp, DT, lam, SPLIT, E, IndexA, DatatypeA, StorageA, orient, DatatypeMix, DatatypeE, localA, localC, l, m, n, k, generalized, radimpl, vector_form, out, RO, OO_less_RO, IndexC, DatatypeC, OO_less_RO_DT, OrderA, OrderC, StorageC, typeA, typeC;
       ...
  91         cp := op(2,sqrfree(cp,lam))
       ...
end proc

(The particular line number may vary with Maple version, the above is Maple 14.01.)

Anyway, that occurs in the code to handle the exact symbolic case. But you mentioned solving numerically. Is the Matrix that you pass to the Eigenvalues command purely numeric? If so, then could you wrap an `evalf` call around that Matrix, like say Eigenvalues(evalf(M))? Doing so might allow it to use floating-point rather than exact methods.

You might need to get rid of small imaginary artiifacts, if Eigenvalues is called on a float Matrix which doesn't have the `symmetric` shape. This can usually be done reasonably safely with some call to fnormal.

13.2 + I*1e-12;
                                         -12  
                              13.2 + 1 10    I
fnormal(%);
                                 13.2 + 0. I
simplify(%);
                                 13.20000000

eigvals := Vector([13.2 + I*1e-12, -2.3 - I*3e-14]):
map(simplify@fnormal, eigvals);
                               [ 13.20000000]
                               [            ]
                               [-2.300000000]

Are you thinking of the `alias` command?

I don't see a crash in Maple 14.01 on Windows XP. What platform and version are you using?

You might want to try shape=symmetric rather than shape=[symmetric], which doesn't seem to make a difference in Maple 14.01 but might in your version if different(?).

Yes, the Matrix has a large condition number. This is a clue that the "rank" may well change with Digits.

But here is something I notice: By wrapping your Matrix M with another call to the `Matrix` constructor you can get rid of the special shape and storage. Eigenvalues(Matrix(M)) shows the very small (close to zero) eigenvalue even using hardware precision. So it looks like the symmetric eigenvalue routine is having issues computing that small eigenvalue, while the nonsymmetric routine does better. The `EigenConditionNumbers` routine show similar difficulty, even though it indicates that the so-called eigenvalue condition numbers are 1. It could be a bug in the CLAPACK symmetric eigenvalue routine.

The following computations show at what precision various quantities settle down for this Matrix M. Since the "linear-system solving" traditional condition number settles down to about 10^49 it makes sense that Digits has to be 10^50 or larger before the rank is indicated as being 6 (full) and the deteminant becomes "accurate". The question of how high Digits must be set in order to get a clear picture of the smallest eigenvalue looks trickier (as the eigen-condition-numbers aren't being helpful).

restart:
M:=Matrix(6, 6, {(1, 1) =
156393396.533701532179918215869026476966,
(1, 2) = -118243903475.827285569404582605530765663,
(1, 3) = -6263333.73617023234383582644338323627622,
(1, 4) = -185091.483826089501251512713737005555751,
(1, 5) = 80790.9801929789813449825471731605781843,
(1, 6) = 1086348.92359099037490942739843407023680,
(2, 2) = 624048841842745.066305236557017731156085,
(2, 3) = -14223324279.9671059208805631179717784309,
(2, 4) = 271390990.212364081029432696123806175245,
(2, 5) = -6789557.78040918751895574011616954335163,
(2, 6) = -887211297.790616808899440297249969343478,
(3, 3) = 942997.103500826358338353949909438447968,
(3, 4) = 2390.98882773656471330090678451501720186,
(3, 5) = -5202.67399895018046545215520415279523662,
(3, 6) = -41059.7545428613547434057144743597172361,
(4, 4) = 258.746505379263550904147446064209326068,
(4, 5) = -80.0681808327239671077263126470862610300,
(4, 6) = -1305.03399424659072471164804998119366346,
(5, 5) = 128.203084138681407601505798776377859168,
(5, 6) = 501.829272012377495290246242165653330606,
(6, 6) = 7588.85431135042280667483054584887636828},
storage=triangular[upper],shape = symmetric):

with(LinearAlgebra):

Eigenvalues(M);
[ -0.0210080540610656]
[ ]
[ 0.836928584471978]
[ ]
[ 114.861391764284]
[ ]
[ 19791.8054590435]
[ ]
[ 8]
[ 1.34594209844555 10 ]
[ ]
[ 14]
[6.24048864572998 10 ]

EigenConditionNumbers(M,output=values);
[ 0.0480281548255764]
[ ]
[ 0.839396433994692]
[ ]
[ 114.891542190737]
[ ]
[ 19791.8054628282]
[ ]
[ 8]
[ 1.34594209844560 10 ]
[ ]
[ 14]
[6.24048864572998 10 ]

sort(Vector(Eigenvalues(Matrix(M)),datatype=float));
[ -9]
[9.89274901407695 10 ]
[ ]
[ 0.837947576455359]
[ ]
[ 114.913646648688]
[ ]
[ 19791.8054606585]
[ ]
[ 8]
[ 1.34594209844602 10 ]
[ ]
[ 14]
[6.24048864572998 10 ]

Rank(M); ConditionNumber(M);
2
27
1.185663136 10

Digits:=17:

Eigenvalues(M);
[ 0.0030250112720963530]
[ ]
[ 0.83809868484295287]
[ ]
[ 114.92118718236513]
[ ]
[ 19791.805459388527]
[ ]
[ 8]
[ 1.3459420984455707 10 ]
[ ]
[ 14]
[6.2404886457299717 10 ]

EigenConditionNumbers(M,output=values);
[ -0.0091835218548658467]
[ ]
[ 0.83767574972930436]
[ ]
[ 114.91587440245346]
[ ]
[ 19791.805458720433]
[ ]
[ 8]
[ 1.3459420984455633 10 ]
[ ]
[ 14]
[6.2404886457299719 10 ]

sort(Vector(Eigenvalues(Matrix(M)),datatype=float));
[ -11]
[-2.2627758723552663 10 ]
[ ]
[ 0.83794757314878879]
[ ]
[ 114.91364664485331]
[ ]
[ 19791.805459337745]
[ ]
[ 8]
[ 1.3459420984455108 10 ]
[ ]
[ 14]
[ 6.2404886457299716 10 ]

Rank(M); ConditionNumber(M);
5
27
1.8096278809518644 10

for Digits from 20 to 60 by 5 do
[Digits, Rank(M), ConditionNumber(M), Determinant(M)];
print(evalf[10](%));
end do:

[ 30 13]
[20., 5., 7.750782748 10 , 1.653658460 10 ]
[ 35 8]
[25., 5., 2.533011832 10 , 5.060042477 10 ]
[ 40 ]
[30., 5., 2.374155877 10 , 5398.612445]
[ 45 ]
[35., 5., 1.185643403 10 , 0.1081028868]
[ 49 ]
[40., 5., 2.562284053 10 , -0.000005002235193]
[ 49 ]
[45., 5., 2.741632430 10 , -0.000004675005782]
[ 49 ]
[50., 5., 2.741633014 10 , -0.000004675004786]
[ 49 ]
[55., 6., 2.741633014 10 , -0.000004675004786]
[ 49 ]
[60., 6., 2.741633014 10 , -0.000004675004786]

evalf[55](sort(Vector(Eigenvalues(Matrix(M)),datatype=float))):
evalf[10](%);
[ -35]
[-2.92054039500000016 10 ]
[ ]
[ 0.837947573200000018]
[ ]
[ 114.913646600000008]
[ ]
[ 19791.8054599999996]
[ ]
[ 8]
[ 1.34594209800000012 10 ]
[ ]
[ 14]
[ 6.24048864600000000 10 ]

evalf[55](Eigenvalues(M)): evalf[10](%);
[ -35]
[-2.92054222699999991 10 ]
[ ]
[ 0.837947573200000018]
[ ]
[ 114.913646600000008]
[ ]
[ 19791.8054599999996]
[ ]
[ 8]
[ 1.34594209800000012 10 ]
[ ]
[ 14]
[ 6.24048864600000000 10 ]

for Digits from 47 to 55 by 1 do
[Digits, min(Eigenvalues(M))];
print(evalf[10](%));
end do:
[ -33]
[47., -4.413383319 10 ]
[ -34]
[48., -4.605859067 10 ]
[ -36]
[49., -8.841409968 10 ]
[ -35]
[50., -3.142806555 10 ]
[ -35]
[51., -2.916933629 10 ]
[ -35]
[52., -2.922580749 10 ]
[ -35]
[53., -2.920321997 10 ]
[ -35]
[54., -2.920491404 10 ]
[ -35]
[55., -2.920542227 10 ]

Digits:=100:
EigenConditionNumbers(Matrix(M),output=[conditionvalues,values]):
evalf[10]([%]);
[ [ 14 ]]
[[1.] [ 6.24048864600000000 10 + 0. I ]]
[[ ] [ ]]
[[1.] [ 8 ]]
[[ ] [ 1.34594209800000012 10 + 0. I ]]
[[1.] [ ]]
[[ ] [ 19791.8054599999996 + 0. I ]]
[[1.], [ ]]
[[ ] [ 114.913646600000008 + 0. I ]]
[[1.] [ ]]
[[ ] [ -35 ]]
[[1.] [-2.92054039500000016 10 + 0. I]]
[ [ ]]
[ [ 0.837947573200000018 + 0. I ]]

The error message you show can arise when there is a mismatch, using the expression form for the ranges alongside a procedure or operator (or appliable module). Eg.

> f := (x,y)->x^2/(x-y):

> plot3d(f, x=-2..2, y=-2..2);
Error, (in plot3d) expected ranges but received equations x = -2 .. 2 and y = -2 .. 2

If you are trying to plot a 2-argument procedure (or operator) then the syntax for the ranges would be like

plot3d(f, -2..2, -2..2);

If you are trying to plot an expression in two variables, then the syntax for the ranges would be like

plot3d(x^2/(x-y), x=-2..2, y=-2..2);

plot3d(f(x,y), x=-2..2, y=-2..2); # since f(x,y) is evaluated to an expression up front

Confusion between expressions and procedures is #1 on Robert Israel's very useful Top Ten Maple Errors list. (Note that the error message for this mistake in the 1D `plot` case is no longer as helpful or instructive in Maple 14 as Robert's worksheet shows that it was in some earlier version.)

As mentioned, you can restrict who may open the worksheet, according to which Cloud "group" you upload it, but you cannot prevent them from saving it once having opened it.

So, the answer to your specific question, "...allow the person just read the worksheet and not download/save in their own computer" seems to be no.

Even if the GUI were altered so as to prevent the viewing user from saving the worksheet using the menubar's File dialogue, it might still be possible to copy and paste the contents into a new, savable sheet. So it looks like the behaviour (exactly as you've stated it) would be difficult to implement in Maple itself.

Getting the stated behaviour might be more closely attained using conversion to another format (eg. pdf, as suggested) or possibly through Maplenet (similarly to how the Online Help is provided).

The solution values fall withing the feasibility tolerance.

Try setting infolevel[Optimization]:=3 or read the help page ?Optimization,options

Note that you likely won't be able to increase Digits much higher than evalhf(Digits) for this problem, as it seems to suffer from a (lack of) garbage collection issue introduced for software float external calling a few releases back.

But even in Maple 10, with Digits:=20 and supplying feasibilitytolerance=1e-20, the returned solution S would still just get values like

 

> eval(w[1],op(2,S));
-20
-0.43000000000000000085 10

As for changing con3 to be w[i] >= 0.01, consider that there are 199 different w[i] variables and con1 says that they must all add up to exactly 1. Check your division!

> 1.0 / nops(indets(lhs(con1),name));
0.0050251256281407035176

So obviously con1 cannot hold if all w[i] are >=0.01

I think that this should be a FAQ.

In order for the plot to be shown, it has to be "printed". That happens if the plot structure is the return value from the proc. But in your example that is not the case. So try printing the plot instead.

Either,

   test := proc(p);
     print(plots:-display(p));
     3; 
   end:

   test(plot(sin(x),x));

or

   test := proc(p);
     print(p);
     3; 
   end:

   test(plot(sin(x),x));

will work.

This is the same technique as can be used for having many plots get "shown" during a proc execution, in a loop inside the proc, say.

One aspect of Documents that I find tricky is creating a 2D Math formula that cannot evaluate.

I don't mean 2D Math inlined into a text section. I mean automatically centered, with a nice equation label. Just like I can get when typesetting a paper in LaTeX.

And it might have to be 2D input (or somehow otherwise inert), since 2D Math output will change undesirably if I subsequently assign to the variables and then inadvertantly execute the worksheet out-of-order. I'm talking about a nicely typeset formula (again, not inlined into a text section) that never changes.

An example is a Matrix equation. This seems to be harder still, as I'd want to raise to power -1 without it becoming a fraction, and transpose (power %T) an unassigned name without it automatically evaluating to merely itself (as some of the names are meant to refer to Matrices).

And I'd really like to be able to do this by typing alone: no mouse action, no block collapsing, no output removal, no palette insertion to get inert superscripted powers. Just typed in, inert Matrix math.

And it should be easy and quite to create. I think that I've seen demos where, in a few cryptic steps, a similar general effect was obtained by inputting, executing, manually removing the 2D output, then maybe collapsing the block... or something like that. I forget eactly, because it wasn't simple. I can't recall whether it obtained an equation label or not. If I recall, it wasn't easy to subsequently edit such an object, without undoing and redoing some of those steps.

I'd be delighted if someone could describe a quick and easy way to get such a centered, typeset, labelled and inert formula into a Document. After all, a Document is supposed to be a means to do scientific write-ups.

Two more links that relate: here and here.

This seems to be a FAQ.

You could try one of these approaches (the first of which has a few variants of its own).

> Test:=Sum(f1(n)+f2(n)+f3(n),n=1..infinity);

                           infinity                       
                            -----                         
                             \                            
                              )                           
                   Test :=   /     (f1(n) + f2(n) + f3(n))
                            -----                         
                            n = 1                         

> map(op(0,Test),op(1,Test),op(2,Test));

             /infinity     \   /infinity     \   /infinity     \
             | -----       |   | -----       |   | -----       |
             |  \          |   |  \          |   |  \          |
             |   )         |   |   )         |   |   )         |
             |  /     f1(n)| + |  /     f2(n)| + |  /     f3(n)|
             | -----       |   | -----       |   | -----       |
             \ n = 1       /   \ n = 1       /   \ n = 1       /

> with(student):
> expand(Test);

             /infinity     \   /infinity     \   /infinity     \
             | -----       |   | -----       |   | -----       |
             |  \          |   |  \          |   |  \          |
             |   )         |   |   )         |   |   )         |
             |  /     f1(n)| + |  /     f2(n)| + |  /     f3(n)|
             | -----       |   | -----       |   | -----       |
             \ n = 1       /   \ n = 1       /   \ n = 1       /

Note that `expand/Sum` gets reassigned when the `student` package is loaded. I haven't seen much discussion as to why the `student` version of `expand/Sum` has this difference.

> L:=[4,6,Pi]:

> map(sin,L);
                      [sin(4), sin(6), 0]

> map(evalf@sin,L);
               [-0.7568024953, -0.2794154982, 0.]

> sin~(L);
                      [sin(4), sin(6), 0]

> (evalf@sin)~(L);
               [-0.7568024953, -0.2794154982, 0.]
> StringTools:-IsAnagram(cat(123456789),cat(847591236));
                              true
First 19 20 21 22 23 24 25 Last Page 21 of 48