## 28100 Reputation

17 years, 244 days

## Cl...

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.

 >
 >
 >

## plane...

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):
Line:=(q,t)->[4*q+(1-4*q)*t,-1+(1-4*q)*t,q+(16*q^2-q)*t]:
F:=Q->plots:-display(
plottools:-line(Line(Q,-1.5),Line(Q,+2.5),color=red,thickness=5),
plot3d([4*q+y+1,y,q+(y+1)*(16*q^2-q)/(1-4*q)],
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,
background=[G1,G2,G3]);
```

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

## something...

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

alle-maple_3_ac1.mw

## one way...

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

some_import.mw

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

## procedure's parameter's type specificati...

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

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

Type_RandomVariable_ac.mw

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:

```restart;
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:

p(Matrix(2));
"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.

```restart;
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:

p(Matrix(2));

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

## example...

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.

## evala...

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

evala(e1);

-1/2*((-4*a*c+b^2)^(1/2)+b)/a
```

simplify_exA.mw

A more involved way, which happens to use simplify,

simplify(expand(rationalize(e1)))

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.

## canonicalization...

Maple performs the following, a kind of canonicalization,

```cot(90 - alpha/2);

-cot(-90+1/2*alpha)```

However,

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

simplify(eq);

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

## right...

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.

```restart;

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

sort(res);

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

res;

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

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

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

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.

## unapply...

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,

## Create...

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

ImageTools:-Create(M)

## scale, then use as background...

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.

## one way...

Here is one way.

 > sort([x,x/3],key=content);

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

## indexing function?...

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

## rtable_scanblock...

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

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

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

First, using just the 3rd row.

 > rtable_scanblock(M[3,..],[1..n],':-NonZeros');

Now, for all rows, and measuring performance.

 > CodeTools:-Usage(    [seq(rtable_scanblock(M[i,..],[1..n],':-NonZeros'),i=1..m)] );

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

 > ZerosInRow := i -> numelems(op(M[i])[2]):
 > CodeTools:-Usage(    [seq(ZerosInRow(i),i=1..m)] );

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

 > with(LinearAlgebra): CodeTools:-Usage(    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