28100 Reputation

29 Badges

17 years, 244 days
Ontario, Canada

Social Networks and Content at

MaplePrimes Activity

These are answers submitted by acer

It's because you misspelled Cl as CL in your call to solve.

By the way, you don't have to specify the variables, in this case.

There may be more than just one single solution.


K1 := 10^(-2.12); K2 := 10^(-7.21); K3 := 10^(-12.32); Kw := 10^(-14); NaCl := .5004/(58.44); NaH2PO4 := .1092/(119.98); Na2HPO4 := 1.214/(141.96); Why := Kw = H*OH; Do := K1 = H*H2PO4/H3PO4; It := K2 = H*HPO4/H2PO4; Today := K3 = H*PO4/HPO4; When := Cl = NaCl; Its := Na = NaH2PO4+2*Na2HPO4+NaCl; Due := Na+H = Cl+3*PO4+2*HPO4+H2PO4+OH; Tomorrow := Na2HPO4+NaH2PO4 = H3PO4+H2PO4+HPO4+PO4

z := solve([Why, Do, It, Today, When, Its, Due, Tomorrow])

{Cl = 0.8562628337e-2, H = 0.6579879116e-8, H2PO4 = 0.9122851784e-3, H3PO4 = 0.7913134254e-9, HPO4 = 0.8548948565e-2, Na = 0.2657618944e-1, OH = 0.1519784760e-5, PO4 = 0.6218631025e-6}, {Cl = 0.8562628337e-2, H = -0.3263250031e-12, H2PO4 = 0.1072896217e-6, H3PO4 = -0.4615386387e-17, HPO4 = -0.2027250253e-1, Na = 0.2657618944e-1, OH = -0.3064429604e-1, PO4 = 0.2973425164e-1}, {Cl = 0.8562628337e-2, H = -0.1607217980e-10, H2PO4 = -0.2542714628e-5, H3PO4 = 0.5387315421e-14, HPO4 = 0.9754900397e-2, Na = 0.2657618944e-1, OH = -0.6221931391e-3, PO4 = -0.2905012846e-3}, {Cl = 0.8562628337e-2, H = -0.2851825413e-2, H2PO4 = 0.1516239135e-1, H3PO4 = -0.5700207123e-2, HPO4 = -0.3278270360e-6, Na = 0.2657618944e-1, OH = -0.3506526015e-11, PO4 = 0.5502015790e-16}, {Cl = 0.8562628337e-2, H = -0.2274751800e-1, H2PO4 = -0.4733982564e-2, H3PO4 = 0.1419582613e-1, HPO4 = 0.1283194935e-7, Na = 0.2657618944e-1, OH = -0.4396084003e-12, PO4 = -0.2699968014e-18}


Why use the heavyweight implicitplot3d construction, in order to produce a plane along x=y?

G1 := plots:-tubeplot([4*t, -1, t], t = -10 .. 10, radius = 0.2, color = blue):
G2 := plots:-tubeplot([1, t, t^2], t = -15 .. 15, radius = 0.2, color = blue):
G3 := plot3d([x, x, z], x = -40 .. 40, z = -400 .. 700,
             color = gray, transparency = 0.7, glossiness = 0):
               q=-4..Q, y=(-2.5+6*q)..(1.5-10*q),
               style=patchcontour, lightmodel=light4, axes=framed)):
plots:-animate(F, [q], q=-4..4, frames=50, lightmodel=light1,

Naturally, you can adjust the ranges, color, transparency, and style, to taste.

Here's something (much more than the Maple 2022.2 GUI recovers.) I suggest that you check it over for missing parts.

Here is one way to deal with the extra "characters".

Does the following get all the valid data? (I didn't try to find a more efficient way. I don't know whether you have to make this scale well for huge examples.)

If that import suffices, do you also need to know how to separate the headers from the numeric data? That's quite straightforward (compared to the character removal step, IMO). You could also search for the first numeric row, or the row with "X:","Y:", etc. Note that not all the header sections have the same number of rows, eg. only some have "PlateletFunction".

Those uneval quotes around the type specification of the procedure's parameter are misplaced.

Try it instead as,

  f1 := proc(A::RandomVariable)
  end proc:

The type is not evaluated in the procedure's parameter's specification (including when invoked), though it is within a procedure's body.

An example where quoting the type may be needed in the procedure's body:

p := proc( M::Matrix(square) )
  if type(M, 'Matrix(square)') then
    print("1st passed");
  end if;
  if type(M, Matrix(square)) then
    print("2nd passed");
  end if;
end proc:

                          "1st passed"
Error, (in Matrix) dimension parameters are required for this form of initializer

[edited] For the sake of clarity I'll add that the absence of evaluation does not come from the double-colon syntax per se. See this Help page. So, revising that example's syntax, the behavior is similar.

p := proc( M::Matrix(square) )
  if M::'Matrix(square)' then
    print("1st passed");
  end if;
  if M::Matrix(square) then
    print("2nd passed");
  end if;
end proc:


                          "1st passed"
Error, (in Matrix) dimension parameters are required for this form of initializer

Does this suffice? (Add checks for other kinds of terms, etc, if needed.)

F := [x^2-z^2, x*y+y*z, x*z-y*z, y^2+y*z,w^2]:

# make it harder
sort~(F, order=plex(z,y,x));

   [-z^2+x^2, z*y+y*x, -z*y+z*x, z*y+y^2, w^2]

map(proc(u) local uu:=sort(u,':-order'=':-plex'(x,y,z));
            if uu::`+` then op(1,uu)=-op(2,uu);
            else uu=0; end if; end proc, F);

   [x^2 = z^2, x*y = -y*z, x*z = y*z, y^2 = -y*z, w^2 = 0]

You didn't say whether it was ok to have such an in-place effect on the terms in F, so I presume it's ok.

You could alternatively sort all of F up front, together in one call, wrt the desired ordering. Then map the conditional, op, etc.

I deliberately sorted otherwise, at the start, so that the problem would be harder -- by having the terms in the sums be stored out-of-order. The point is that you don't want to rely on the good fortune that they might just happen to already appear in your desired order.

e1:= -(b*(b^2 - 4*a*c)^(1/2) - 4*a*c + b^2)/(2*a*(b^2 - 4*a*c)^(1/2)):



A more involved way, which happens to use simplify,


You asked about a "general" way. The presence of the radical in the denominator is key, in the given example. The evala command is often useful in such cases -- sometimes more directly so than rationalize.

Maple performs the following, a kind of canonicalization,

cot(90 - alpha/2);



eq := x = -sin(alpha)*(L + (e + r)/tan(-Pi/4 + alpha/2))/2 + sin(alpha)*L:


   x = 1/2*((e+r)*tan(1/4*Pi+1/2*alpha)+L)*sin(alpha)

Maple stores only one instance of the polynomial in memory. That allows it to be immediately recognized as being the same instance -- wherever it earlier appeared -- which is a basic aspect of Maple crucial to efficiency.

And sort acts in-place on that stored instance.

Notice that this uniquification also takes place if you re-enter the expression.


res:= x^2 + x + 1 + 1/3*x^3 + 1/12*x^4 + 1/60*x^5 + 1/360*x^6 + 1/2520*x^7;






x^2 + x + 1 + 1/3*x^3 + 1/12*x^4 + 1/60*x^5 + 1/360*x^6 + 1/2520*x^7;


It would be catastrophically bad for Maple if it has to walk multiple instances of such expressions whose terms were differently ordered, whenever it has to test that they were equivalent.

This behavior is documented on the Help page for sort, which states in its Description section,

   Note: Sorting polynomials is a destructive operation: the input polynomial is sorted "in-place".

That Help pages also states, in its Thread Safety section,

   The sort command is thread safe as of Maple 15, provided that a polynomial is not being sorted.  Sorting polynomials is not thread safe.

Try it as,

   f := unapply(PolynomialFit(4, M, x), x);

ps. FYI, the word function has a technical meaning in Maple, which is different from this. A better term in the context of Maple (and which you used in your title), is that you want to create a procedure or operator from the returned expression. That could then be applied to arguments, eg, f(3), etc,

If M is your Matrix with all entries of type numeric then,


You could use the background option of the plot command, with ranges set according to image dimensions.

Then you get the usual 2-D plot point-probe facilities.

You could scale down the image (max. used dimension <300, say), and retain aspect ratio, to reduce burden on GUI.

Flip/flop as needed.

Here is one way.


[(1/3)*x, x]

If you have trouble using this more generally then the cause is your lack of a correspondingly more general example.

Perhaps you could set up a custom indexing function, used alongside storage=sparse.

You could use the rtable_scanblock command for this.

(I'll add a timing, to compare with some other suggestions. It's not clear whether you need it to be very quick.)


(m,n) := 6,10^5;

6, 100000

M := LinearAlgebra:-RandomMatrix(m,n,density=0.3):


First, using just the 3rd row.





Now, for all rows, and measuring performance.



memory used=4.58MiB, alloc change=3.06MiB, cpu time=18.00ms, real time=17.00ms, gc time=0ns

[29954, 29739, 29751, 29914, 29949, 29709]

ZerosInRow := i -> numelems(op(M[i])[2]):


memory used=18.05MiB, alloc change=7.53MiB, cpu time=138.00ms, real time=138.00ms, gc time=69.12ms

[29954, 29739, 29751, 29914, 29949, 29709]

   nops~(select~(x -> x <> 0, convert~([Row(M, [1 .. RowDimension(M)])], list)))

memory used=29.58MiB, alloc change=12.87MiB, cpu time=200.00ms, real time=200.00ms, gc time=0ns

[29954, 29739, 29751, 29914, 29949, 29709]


4 5 6 7 8 9 10 Last Page 6 of 292