acer

32405 Reputation

29 Badges

19 years, 350 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

@Tycho Brahe You can download the installer for the Maple 2022.2 update here.

It helps to use another range.

restart;

TWeq := 2.96736996560705*10^(-12)*p^2+1.31319840299485*10^(-13)*t^2
        -8.89549693662593*10^(-7)*p+8.53128393394231*10^(-7)*t
        -3.65558815509970*10^(-30)*p*t-1 = 0:

plots:-implicitplot(TWeq, p = -2e6 .. 2e6, t = -1e7 .. 1e7,
                    scaling=constrained);

Download ellipse_rng.mw

It's not entirely clear to me what you mean.

But you could use add, or a do-loop, as follows.

restart;

S1 := 441;
S2 := 1109;
S3 := 511;
S4 := 900;
S5 := 2904;
S6 := 285;

441

1109

511

900

2904

285

S2 + S3 + S4 + S5 + S6;

5709

add(S||i, i=2..6);

5709

S[1]:=0;
for i to 5 do
    S[i+1]:=S[i] + S||(i + 1);
end do;

0

1109

1620

2520

5424

5709

S1 + S2 + S3 + S4 + S5 + S6;

6150

add(S||i, i=1..6);

6150

S[1]:=S1;
for i to 5 do
    S[i+1]:=S[i] + S||(i + 1);
end do;

441

1550

2061

2961

5865

6150

Download simple_sum.mw

You recently mentioned that SMTLIB was not working properly on your Windows 10 machine. 

The command SMTLIB:-Satisfiable gets called on your example(s), returning false on my Maple 2023.0 for Linux.

I suspect that you might be seeing that FAIL result in consequence. Here is the trace of that command for the last example.

restart;

kernelopts(version);

`Maple 2023.0, X86 64 LINUX, Mar 06 2023, Build ID 1689885`

_EnvTry := hard:

assume(Or(n < 0, 1 <= n), n*(n - 1)/2 < m);

is(m<0);

false

is(m>0);

true

trace(SMTLIB:-Satisfiable):

coulditbe(m,0);

{--> enter SMTLIB:-Satisfiable, args = {Or(1 <= n_2, n_2 < 0), m_1 = 0, 0 < m_1-(1/2)*n_2^2+(1/2)*n_2}, timelimit = .25

["sat.random_seed" = "736602622344", "smt.random_seed" = "329844591802"]

.25

["sat.random_seed" = "736602622344", "smt.random_seed" = "329844591802", "timeout" = "250"]

"(declare-fun V1 () Real)
(declare-fun V2 () Real)
(assert (and (or (<= 1 V2) (< V2 0)) (= V1 0) (< 0 (+ V1 (* (* V2 V2) (/ (- 1) 2)) (* V2 (/ 1 2)))) (<= 1 V2) (< 0 (+ V1 (* (* V2 V2) (/ (- 1) 2)) (* V2 (/ 1 2))))))
(check-sat)
(exit)
", symtab, typetab

false

<-- exit SMTLIB:-Satisfiable (now in \`is/internal/SMTLIB\`) = false}

{--> enter SMTLIB:-Satisfiable, args = {Or(1 <= n_2, n_2 < 0), m_1 = 0, 0 < m_1-(1/2)*n_2^2+(1/2)*n_2}, timelimit = .25

["sat.random_seed" = "559705322288", "smt.random_seed" = "759661297346"]

.25

["sat.random_seed" = "559705322288", "smt.random_seed" = "759661297346", "timeout" = "250"]

"(declare-fun V1 () Real)
(declare-fun V2 () Real)
(assert (and (or (<= 1 V2) (< V2 0)) (= V1 0) (< 0 (+ V1 (* (* V2 V2) (/ (- 1) 2)) (* V2 (/ 1 2)))) (< 0 (+ V1 (* (* V2 V2) (/ (- 1) 2)) (* V2 (/ 1 2)))) (< V2 0)))
(check-sat)
(exit)
", symtab, typetab

false

<-- exit SMTLIB:-Satisfiable (now in \`is/internal/SMTLIB\`) = false}

false

Download Unable_to_prove_ac.mw

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.

restart

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}

Download Chem_ac.mw

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.

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

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

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

Try it instead as,

  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

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

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.

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)

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.

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,

    ImageTools:-Create(M)

First 48 49 50 51 52 53 54 Last Page 50 of 336