acer

32313 Reputation

29 Badges

19 years, 315 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

To answer your question, I suspect that it is "known" since I recall earlier reporting a similar example.

But I will submit this example anyway. (In 2020.1 the call solve(sol, allsolutions) produces it.)

How about something like the following, using evalc to deal with csgn beforehand.

new := simplify(evalc(sol))=0 assuming real:

    -(a-x)^2*(-abs(-1+(a-x)*_C1)-1+(a-x)*_C1)/(k+1)/abs(-1+(a-x)*_C1)^3 = 0

S := [solve(new, allsolutions, real)]:
map(lprint, S):
{_C1 = _C1, a = x, k = k, x = x}
{x = x, -1 < k, _C1 < 0, a < (_C1*x+1)/_C1}
{x = x, -1 < k, 0 < _C1, (_C1*x+1)/_C1 < a}
{x = x, _C1 < 0, a < (_C1*x+1)/_C1, k < -1}
{x = x, 0 < _C1, k < -1, (_C1*x+1)/_C1 < a}

map(proc(s) local eqs, ineqs;
      eqs,ineqs := selectremove(type,s,`=`);
      simplify(eval(sol,eqs)) assuming ineqs[];
    end proc,
    S);

             [0, 0, 0, 0, 0]

simplify_real_solve_examp.mw

Then adjust as appropriate (including for other examples, of course).

That is because the length command does not return the number of elements of a Vector or a Array. You have used the wrong command.

Instead, you could use the numelems command here, eg.
   numelems(R1);

Since R1 in your example is a row Vector, you could also use these commands,
   LinearAlgebra:-Dimension(R1);
   op(1,R1);
 

Does it work if you first execute the command,

     interface(prettyprint=3):

If so then you might need to set that as
  Tools->Options->Display->Output Display->2D Math Notation
rom the main menubar. Then save preferences using the Apply Globally button.

You might possibly also need to shut and relaunch the GUI altogether.

You have compared an equation in Maple  (ie. =) with an equality test in Mathematica (ie. ==). That comparison of those two quite different intended functionalities is not justified.

A mathematical comparison can be done using the is command (as Kitonum mentioned).

f:=(9*(x^(-2/3*a))^2*exp(6/a*(x^(-2/3*a))^(1/2))^2*_C0^2-6*(x^(-2/3*a))^(3/2)*exp(
6/a*(x^(-2/3*a))^(1/2))^2*_C0^2*a+x^(-2/3*a)*exp(6/a*(x^(-2/3*a))^(1/2))^2*_C0^
2*a^2+18*(x^(-2/3*a))^2*exp(6/a*(x^(-2/3*a))^(1/2))*_C0-2*x^(-2/3*a)*exp(6/a*(x
^(-2/3*a))^(1/2))*_C0*a^2+6*(x^(-2/3*a))^(3/2)*a+x^(-2/3*a)*a^2+9*(x^(-2/3*a))^
2)/(3*_C0*exp(6/a*(x^(-2/3*a))^(1/2))*(x^(-2/3*a))^(1/2)-exp(6/a*(x^(-2/3*a))^(
1/2))*_C0*a+3*(x^(-2/3*a))^(1/2)+a)^2:

g:=x^(-2/3*a):

is(f=g);
                    true

The comparion using evalb is merely structural in this case. It is weaker to place the additional burden of both expressions "simplifying" to the same canonical form (if it exists) than to test whether their difference is mathematically zero. This is important. You should not make your primary approach be such a test of separate simplification to the same expression.

Having said that, both parts of the given example can be simplified to the same expression (though not directly in just one call to the simplify command).

And the given example can be done with a straightforward nesting of 2 or 3 simplifying commands. That is achievable in several different ways. It doesn't require ad hoc substitution or any restrictive assumption (both of which Kitonum used in his answer).

For example, using Maple 2020.1,

simplify(expand(rationalize(f)));

                   (- 2/3 a)
                  x          

There are other, even shorter ways to get that, some involving calls that generally involve less computational effort. For example,

normal(radnormal(f));
                            (- 2/3 a)
                           x         

expand(radnormal(f));
                            (- 2/3 a)
                           x         

normal(expand(rationalize(f)));
                            (- 2/3 a)
                           x         

And these more generally more computationally intensive forms follow from those,

simplify(radnormal(f),size);
                            (- 2/3 a)
                           x         

simplify(radnormal(f));
                            (- 2/3 a)
                           x         

Another terse approach here is:

evala(Normal(f));
                            (- 2/3 a)
                           x         

I shall submit a bug report against simplify, for this example.

[edit] Some additional notes:
 - There are some cases where is(A-B=0) does better than is(A=B), but I don't recall ever seeing the opposite case.
 - There are some rare cases where is(simplify(A-B)=0) does better than is(A-B=0) , but those have become even more rare in past years.
 - Generally is is stronger than just simplify, by which I mean that generally is(A-B=0) does better than evalb(simplify(A-B)=0) .
 - There have always been some relatively uncommon examples where some mix of simplify, rationalize, expand, combine, evala, and radnormal do better at zero recognition than does simplify alone.

You can use the plots:-display command to combine several plots, for example the curve, more than one point plot, and more than one textplot.

If this is not a homework question whose goal is get you to learn how to do all those things together, then you might also look at the FunctionChart command.

(You didn't provide the actual example, which isn't very helpful.)

Your procedure f may not be written to allow for the case that its passed argument x does not (yet) have a numeric value.

Note that Maple's usual evaluation rules for procedure calls is that the arguments are evaluated up front. That means that the call f(x) in your fsolve call gets evaluluated before x takes any numeric value.

But this call, for symbolic name x, returns your error. That is what fsolve sees. This is the primary problem. The call to f(x) is evaluated prematurely.
   f(x);
Error, (in ValveLaminarMassFlow_proc) cannot determine if this expression is true or false: 10000.0 <= 8848.331994*x

There are some other complications, but to keep it brief: Here is one way, using the operator-form calling sequence of fsolve, rather than the expression-form.   fsolve_if_then_not_evaluating_in_proc_ac.mw

That gives the result 13.95e-3 which seems to agree with the plot from,
   plot(x -> [f(x)][1] - x, 0 .. 0.02)

In Maple 2020, with default interface(typesetting=extended) the name Change appears by itself, in the output printed in the Java GUI for that unevaluated function call. But if I set,
    interface(typesetting=standard):
then the fully qualified name IntegrationTools:-Change is shown on that unevaluated function call.

If I use Maple 2016 (say), in which the default was typesetting=standard, then even there I can suppress the package name in that unevaluated fucntion call in output, by first forcing typesetting=extended via kernelopts.

You didn't mention which version you are using. I don't know whether using typesetting=extended is acceptable for you, or whether it would have some other effect that you don't like.

The bytesused number (shown by CodeTools:-Usage) refers to how much memory has been processed by Maple's garbage collector, during the computation. This doesn't relate directly (or meaningfully, IMO) to the amount of resident memory in use, let alone the peak of that.

The bytesalloc number (shown by CodeTools:-Usage) refers to the difference in how much of the OS memory is allocated by the Maple kernel -- comparing the end against the start of the computation. (This number can sometimes be reported as negative, if garbage collection has freed up memory back to the OS during the computation -- not common, but possible.) This quantity relates to memory allocation, but is not an indicator of peak allocation over a computation.

 

Perhaps you want to do something more like this?

I am guessing here. I have moved the end if, and use sum1[n-1] on the right-hand side of that problematic assignment, and initialize sum1[-11] to zero.

new_ac.mw

Here is one way, using algsubs instead of subs:

restart;
eq_5 := x = -(K_i*Zs - Z_AB - Zs)/(K_i*Z_AB);

                              K_i Zs - Z_AB - Zs
                eq_5 := x = - ------------------
                                   K_i Z_AB     

eq_5_m5 := x = expand(rhs(eq_5));

                               Zs     1       Zs   
             eq_5_m5 := x = - ---- + --- + --------
                              Z_AB   K_i   K_i Z_AB

expand(algsubs(Zs/Z_AB = K_S, rhs(eq_5_m5 )));

                                1    K_S
                        -K_S + --- + ---
                               K_i   K_i

Q20210103_ac.mw

[edit] It's worth noting that the expression Zs/Z_AB is not structurally present as a subexpression of Zs/(K_i*Z_AB) as stored in memory by the Maple engine. Yes, the former divides nicely into the latter, but the former is not structurally present in the latter. That's why your attempt using subs failed. The subs command does syntactic rather than "algebraic" substitution. (It's a frequent mistake, to try and use subs for all manner of mathematical substitutions.) See the Help page for algsubs, for some more examples.

Btw, your example could also be handled by simplify-with-side-relations, eg.

expand(simplify( rhs(eq_5_m5 ), {Zs/Z_AB = K_S}));

What you are encountering is an artefact of the printing of a Vector (or Matrix).

If you programatically access the entries of u then you will get results containing the current running value of the m parameter. Hence, if that is what you mean by "automating calculuations" then you may be good to go. This works because the entries are fully evaluated upon access.

If you have a program which needs to do a very large number of such accesses of a Vector/Matrix which contains such a parameter (subsequently assigned a new value) then you can do the full evaluations altogether, up front, which can be more efficient. The rtable_eval command provides this functionality.

This also happens to allow printing to display as you wanted, since the ensuing Vector (newly created by the rtable_eval command) doesn't contain the unevaluated name of the parameter.

Pay attention also to the fact that once you instantiate the Vector at a given value of the parameter then such new Vectors don't reflect those new values. But the original u Vector does.

restart;

u := <-2+m,3+m>;


                       [-2 + m]
                  u := [      ]
                       [3 + m ]

m := 5;

                       m := 5

u;

                      [-2 + m]
                      [      ]
                      [3 + m ]


u[1], u[2];

                        3, 8

T := rtable_eval(u);


                          [3]
                     T := [ ]
                          [8]

T;

                        [3]
                        [ ]
                        [8]

# Notice the name of the parameter
lprint(u);
Vector[column](2,{1 = -2+m, 2 = 3+m},datatype = anything,storage = rectangular,
order = Fortran_order,shape = [])

# Notice the absence of the name of the parameter
lprint(T);
Vector[column](2,{1 = 3, 2 = 8},datatype = anything,storage = rectangular,order
= Fortran_order,shape = [])

m := 17;

                      m := 17

u[1], u[2];

                      15, 20

T[1], T[2];

                       3, 8

Vector_rtable_eval.mw

Another way to produce a new Vector instantiated at the current value of the parameter is to map the eval command across it. Eg, map(eval, u) .

The behaviour you encountered in the printing of a Vector (or Matrix, or Array) is due to efficiency reasons: that structure is not fully evaluated entry-by-entry (and no full copy is made) each time it gets passed in a procedure call -- including passage to the printing procedures.

You could increase working precision. One root is so close to 1.0 that default Digits=10 is inadequate.

Digits:=16:

ans := fsolve(r2,ksi);

                   ans := 0.9999999999994157

eval((rhs-lhs)(r2), ksi=ans);

                                       -8
                       1.37357117458 10  

You could also make Digits greater still, and obtain higher accuracy.

II.01_ac.mw

You can construct a procedure which returns unevaluated when called with nonnumeric arguments returns unevaluated. You can then pass that around like an expression (if you want).

In the attached worksheet, I construct a procedure F_yX with parameters y and X. It computes the numeric integral for x=0..X and after substituting the given value of y.

You can construct other, similar, procedures, according to whether you want to compute a double integral (y=0..Y, x=0..X, or whatever), or a single integral y=0..Y for a fixed x value. There are other variants of this approach, depending on what you want as integration bounds, etc.

You haven't properly explained how you intend on using the result, which makes it difficult to cover all possibilities in an answer.

If this is not sufficient then you should explain properly what you mean when you write, "...i need an expression for v to use another place, i do need required its numeric value".

Integration_Help_ac.mw

By the way, it might be the case that exact symbolic integration is possible (or numeric integration is more stable) if you could manipulate or "simplify" the integral before all those coefficients appear as floats. This may be to complicated for you (...we've been here before...).

Your expressions contain some terms raised to the power 1.0 (a float) which may interfere with a straightforward exact symbolic solution. I edited, and removed that effect.

The oldest version I have onhand is Maple 16, and you could try the attached worksheet in your older Maple 11.

I also changed names gamma to lgamma and D to lD, just to avoid (unlikely) collision with the special names that already have meaning to Maple.

E_ac.mw

The explicit solution attained contained this,

[X = sqrt(2)*sqrt(X1), Y = (2*I)*sqrt(2)/sqrt(Pi)]

The inverse of StringTools:-Encode is StringTools:-Decode (as Tom and the OP also mentioned). The inverse of sprintf is sscanf (as vv also mentioned).

f := sqrt(x);    # assumed to be unknown

                                (1/2)
                          f := x     

u  := sprintf("%Zm", f);  # "process" P1

                      u := "*$%"xG#"""""#"

s  := StringTools:-Encode(u,':-base64');  # "process" P2

                  s := "KiQlInhHIyIiIiIiIw=="

# The "inverse" of P2 is
v := StringTools:-Decode( s, 'encoding' = ':-base64' );

                      v := "*$%"xG#"""""#"

sscanf(v, "%m")[];

                              (1/2)
                             x     

The reason that "%Zm" is used in the sprintf formatting string is a backwards compatibility issue. If I recall correctly, when the DocumentTools:-Layout:-Equation procedure was developed the GUI dealt with an older "dotm" (a.k.a. ".m") encoding with some subtle differences compared with how the kernel (and sprintf) deals with some newer polynomial DAG structures. Since the generated XML has to appease the GUI, "%Zm" rather than "%m" was used.

 

First 96 97 98 99 100 101 102 Last Page 98 of 336