acer

29759 Reputation

29 Badges

19 years, 316 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

The z that is the named parameter of your procedure,
    v := z -> functionList[1]
has nothing to do with the global name z that is in the expressions in the set. That's why your attempt does not succeed; invoking that procedure does not replace the z in the expression.

Here are two ways, the second a correction to your procedure-building approach, and the first a simpler approach using eval.

restart;

functionList := {2 + z, z^2 - 3*z, -z^3 + 4}:


Easier way, IMO.

plot3d(Im(eval(functionList[1],z=x + y*I)), x = -1 .. 1, y = -1 .. 1);

v := unapply(functionList[1],z):

plot3d(Im(v(x + y*I)), x = -1 .. 1, y = -1 .. 1);


Note that the following produce the same result as each other,
and are both what can get passed straight to plot3d as its
first argument (if you were to use the second element of your set).

The first method is considerably simpler. It is unnecessary
extra effort to construct a procedure/operator v
and then to only call it once (merely to construct the argument
passed to plot3d).

Im(eval(functionList[2],z=x + y*I))

Im((x+I*y)^2-3*x)-3*Re(y)

v := unapply(functionList[2],z):
Im(v(x + y*I));

Im((x+I*y)^2-3*x)-3*Re(y)

Download unapp_ex.mw

Is this one of the kinds of animation of the curves that you mean?

See attachment for animation of t vs x(t), t vs y(t), with all three playable together and axes aligned. Adjust as wanted.

caring_phase_pemanenan_predator_dgn_parametersesuai_jurnal_ac.mw

There seem to be quite a few "corner cases", what with automatic-simplification, GUI rendering quirks, etc.

(I did this quickly, without cleaning it up. Check for mistakes...)

restart;

H := proc(ee) local res;
  res := subsindets(combine(simplify(ee)),`*`^fraction,
                    proc(u)
                       `if`(denom(op(2,u))=2,
                            surd(op(1,u)^numer(op(2,u)),denom(op(2,u))),
                            %surd(op(1,u)^numer(op(2,u)),denom(op(2,u))));
                    end proc)
         assuming positive;
  subsindets(res, {name,name^integer}^fraction,
             proc(u) local p,r,res; uses ID=InertForm:-Display;
               p := iquo(numer(op(2,u)),denom(op(2,u)),'r');
               if denom(op(2,u))=2 then
                 (op(1,u)^p)*ID((op(1,u)%^(r/denom(op(2,u)))),
                                'inert'=false);
               else
                 (op(1,u)^p)*surd((op(1,u)^r,denom(op(2,u))));
               end if;
             end proc);
end proc:

 

 

H(sqrt(a^3*b^5))

a*b^2*(a*b)^(1/2)

H(sqrt(x^6*y^5*z^5))

x^3*y^2*z^2*(y*z)^(1/2)

H(sqrt(x^6*y^4*z^5))

0, "%1 is not a command in the %2 package", _Hold, Typesetting

H(sqrt(x^6*y^5*z^4))

0, "%1 is not a command in the %2 package", _Hold, Typesetting

H((a^4*b^7*c^3)^(1/3))

a*b^2*c*%surd(a*b, 3)

H((a^4*b^6*c^3)^(1/3))

a*surd(a, 3)*b^2*c

H((a^4*b^8*c^3)^(1/4))

a*b^2*surd(c^3, 4)

H((a^9*b^8*c^3)^(1/4))

a^2*b^2*%surd(a*c^3, 4)

H((a^8*b^8*c^2)^(1/4))

0, "%1 is not a command in the %2 package", _Hold, Typesetting

H((a^9*b^8*c^2)^(1/4))

0, "%1 is not a command in the %2 package", _Hold, Typesetting

H((a^9*b^2*c^2)^(1/4))

a^2*surd(a, 4)*(b*c)^(1/2)

Download example_2_acF.mw

Your attempt to get the overall vertical min&max with,

   plottools:-getdata(A)[3][.., 2]

is faulty because you have multiple curves structures in the plot.

But rather that fix that approach (ie. get the min&max for each and then compare/combine) you could use the rangesonly option of getdata which will figure out the overall min&max in both directions. Ie,

   ymin, ymax := op(plottools:-getdata(P, rangesonly)[2])

vertical_and_horizonatl_line_help_ac.mw

If I plot the surface at a higher grid resolution, in only a narrow strip close to x=-1 then it appears that the surface is discontinuous along x=-1, for y>1.5.

Using implicitplot instead of contourplot seems to provide a useful mechanism for getting the contours to agree with the surface in that region.

I'll leave it to you to figure out whether the apparent discontinuities are (perhaps?) due in part to numeric roundoff issues due to the complicated scaling of factors (ie. exp calls, and very large/small coefficients). I don't see offhand how symbolic manipulation of the expression (even with exact rationals) sheds light there.

sai_1_ac.mw

 

You seem to have omitted to supply a value for y.

For example,

UnivariateBarGraph(beta, [seq(0..1, 0.2)],
                                   [Q = 1.3015, lambda = 0.9989, x = 0, Br = 1, y=1/10], "Chartreuse");

Is this the kind of plot you had in mind?

Test_date_ac.mw

Naturally, you can apply additional options and adjust the axis labels, etc.

@2cUniverse You can fix your problem with the first Button press by doing any of the following:

1) Move the calls to with(...) to before the use...end use, but keep them inside the Button's "click action" code.
pb-App_0.1_ac1.mw
This is somewhat inefficient since it calls with() each and every time the Button is pressed -- which is unnecessary since that's just an initialization step which only needs doing once per restart.

2) Move the with(...) calls outside of the Button altogether, to someplace else in the worksheet. Here I put it in the worksheet's Startup region, so that it's not visible when looking at the worksheet's body. (I'm guessing that you won't people being being distracted by the code, whether its outright visible or even just buried in some Code-Edit Region.)
pb-App_0.1_ac2.mw
For fun I've thrown in a call to randomize() here, which has the effect of making a different set of random values (and, here, plots) be generated after any restart or reopening of the sheet. This make the first plot be different from the previous session's first plot.

You could use the ParseTime command in the StringTools package.

For example,

restart;

str := cat("9/7/2023", "10:22");

"9/7/202310:22"

G :=StringTools:-ParseTime("%m/%d/%Y%l:%M", str);

Record(calendar = "Gregorian", second = 0, minute = 22, hour = 10, monthDay = 7, month = 9, year = 2023, weekDay = 5, weekDayName = "Thursday", yearDay = 250, `dst?` = false)

G:-year;

2023

G:-month;

9

G:-monthDay;

7

G:-hour;

10

G:-minute;

22

Download ParseTime_ex0.mw

Adjust as needed. (You could also add a separator between the year and the hour, or add more fields, etc.)

The axis labels part can be had by,

  labels=[`x `(InertForm:-Display(10%^8,inert=false)*Unit(m)),
                `t `(s)]

which gets upright Roman m, italic x,s,t, a space before the opening brackets, and 10^8 in upright Roman without automatic simplification to 100000000.

Using `10`^8 is shorter to type, but the concession is that the 10 is in italics. Alternatives which also show the 10 in upright Roman include,
  InertForm:-Display(10)^8
  `#mn("10");`^8
  Typesetting:-mn("10")^8

The following solutions found by solve can be tested by resubstituting and simplifying.

restart

NULL

u[1] := -(-2*p^3*sigma^3*y^4+4*k*p^2*sigma^2*y^3+4*p^2*sigma^2*y^3-3*k^2*p*sigma*y^2-4*q*sigma^3*y^2-6*k*p*sigma*y^2+k^3*y-3*p*sigma*y^2+3*k^2*y+3*k*y+y)/(8*sigma^3)+A*y+B

sols := simplify([solve({u[1] = 0, eval(u[1], sigma = -sigma) = 0}, explicit)])

[{A = A, B = 0, k = k, p = p, q = q, sigma = sigma, y = 0}, {A = A, B = -(1/4)*p^3*y^4-(1/2)*y^2*q-A*y, k = -1, p = p, q = q, sigma = sigma, y = y}, {A = A, B = -(5/32)*(((16/5)*q*y+(32/5)*A)*sigma^3+I*(k+1)^3)*y/sigma^3, k = k, p = ((1/2)*I)*(k+1)/(y*sigma), q = q, sigma = sigma, y = y}, {A = A, B = (5/32)*y*((-(16/5)*q*y-(32/5)*A)*sigma^3+I*(k+1)^3)/sigma^3, k = k, p = -((1/2)*I)*(k+1)/(y*sigma), q = q, sigma = sigma, y = y}]

seq(simplify(eval([u[1], eval(u[1], sigma = -sigma)], s)), s = sols)

[0, 0], [0, 0], [0, 0], [0, 0]

Download help_c_solve.mw

Here's one way. I tried to focus on making it easier to understand, instead of using fancy terse syntax or making it super efficient.

restart;

mylist := [x^4 + (-4*m - 7)*x^3 + (m + 4)*x^2 + (3*m - 5)*x, x^4 + (-4*m - 7)*x^3 + (m + 5)*x^2 + (5*m - 7)*x, x^4 + (-4*m - 7)*x^3 + (m + 5)*x^2 + (7*m - 5)*x, x^4 + (-4*m - 7)*x^3 + (2*m + 5)*x^2 + (3*m - 5)*x, x^4 + (-4*m - 7)*x^3 + (3*m + 1)*x^2 + (7*m - 10)*x, x^4 + (-4*m - 5)*x^3 + (2*m + 1)*x^2 + (7*m - 9)*x]:

L := map~(normal, mylist):

ans := [seq([ L[i], diff(L[i],x),
              solve([ eval(diff(L[i],x),x=2),
                      eval(diff(L[i],x,x),x=2)>0 ], m) ],
            i = 1 .. nops(L))]:

print~(ans):

[x^4-(4*m+7)*x^3+(m+4)*x^2+(3*m-5)*x, 4*x^3-3*(4*m+7)*x^2+2*(m+4)*x+3*m-5, {m = -1}]

[x^4-(4*m+7)*x^3+(m+5)*x^2+(5*m-7)*x, 4*x^3-3*(4*m+7)*x^2+2*(m+5)*x+5*m-7, {m = -1}]

[x^4-(4*m+7)*x^3+(m+5)*x^2+(7*m-5)*x, 4*x^3-3*(4*m+7)*x^2+2*(m+5)*x+7*m-5, {m = -1}]

[x^4-(4*m+7)*x^3+(2*m+5)*x^2+(3*m-5)*x, 4*x^3-3*(4*m+7)*x^2+2*(2*m+5)*x+3*m-5, {m = -1}]

[x^4-(4*m+7)*x^3+(3*m+1)*x^2+(7*m-10)*x, 4*x^3-3*(4*m+7)*x^2+2*(3*m+1)*x+7*m-10, {m = -2}]

[x^4-(4*m+5)*x^3+(2*m+1)*x^2+(7*m-9)*x, 4*x^3-3*(4*m+5)*x^2+2*(2*m+1)*x+7*m-9, {m = -1}]

# For each `ee` in `ans`,
#   diff(ee[1],x)=ee[2] is 0 at x=2,
# and
#   diff(ee[1],x,x)=diff(ee[2],x) is positive at x=2

seq(eval([ee[2],diff(ee[2],x)],[x=2,ee[3][]]), ee=ans);

[0, 18], [0, 20], [0, 20], [0, 18], [0, 50], [0, 34]

Download minhthien_s1.mw

[edit] This is also not efficient. But, since you asked, it uses the prime notation for differentiation in 2D Input, and applies at argument 2 (instead of evaluating at point x=2).
minhthien_s2.mw

I did not look for any pattern in the entries of mylist (as a possible shortcut to the solutions, say). I don't know whether you have any rules for forming those entries.

Here's one way to get a more accurate plot. See attachment.

This is an interesting plot. (Is it meaningful, in terms of the as-yet unstated background theory here?)

Reza_Tchno_v3_ac.mw

Have you investigated the system symbolically, possibly using exact rationals? That might possible be able to demonstrate the feasible bounds for alpha, or piecewise explicit formulae, etc.

Do you know whether there is only ever a single solution that satisfies all the constraints?

Do you know for sure that it wouldn't be possible to churn out a relatively simple piecewise solution (in terms of alpha, say), that might be super fast to compute/plot?

Are you interested in finding the critical alpha values?

Have you considered trying to use purely floating-point optimization (eg. alpha->1 as constant objective, and the rest as mixed equality/inequating constraints, thus leveraging Optimization:-Minimize to compute/find a feasible point), for better speed?

Here's one way to handle your given polynomial example.

expr := x^3 + (-m - 1)*x^2 + (-4*m - 3)*x;

x^3+(-m-1)*x^2+(-4*m-3)*x

map(s->sign(s)*normal(s*sign(s)), expr);

x^3-(m+1)*x^2-(4*m+3)*x

Download sgn_ex.mw

ps. You gave the target form as x^3 - (m-1) x^2 - (4m + 3) which isn't equivalent to your input expression. And so I have guessed as to what you wanted to accomplish with the coefficients.

restart

ts := [csc = (proc (u) options operator, arrow; 1/sin(u) end proc), sec = (proc (u) options operator, arrow; 1/cos(u) end proc), cot = (proc (u) options operator, arrow; 1/tan(u) end proc)]


Expression to apply an identity to:

orig := JacobiSN(sin((1/2)*`ϕ__0`)*t, csc((1/2)*`ϕ__0`))

JacobiSN(sin((1/2)*varphi__0)*t, csc((1/2)*varphi__0))

(1)

We don't need to solve anything at this stage. We may simply assert that z,k equal the
arguments of JacobiSN in orig.
We can then quite reasonably utilize the general form Jacobi(z,k) later below.

C := eval({k = op(2, orig), z = op(1, orig)}, ts)

{k = 1/sin((1/2)*varphi__0), z = sin((1/2)*varphi__0)*t}

(2)

Next, without having to cook up 1/k in Jacobi(z,1/k) ourselves
(which would make a somewhat ad hoc approach), which happens
to arise from the LHS of the 5th identity.

This obtains a formula with general Jacobi(z,k) on the LHS.

temp := convert(FunctionAdvisor(identities, JacobiSN(__A, __B))[5], `global`); solve([z = op(1, lhs(temp)), k = op(2, lhs(temp))], [__A, __B])[1]; eqn := subs(%, temp)

JacobiSN(z, k) = JacobiSN(z*k, 1/k)/k

(3)

Easy way,

orig = subsindets(orig, specfunc(JacobiSN), proc (u) options operator, arrow; eval(rhs(eqn), C) end proc)

JacobiSN(sin((1/2)*varphi__0)*t, csc((1/2)*varphi__0)) = sin((1/2)*varphi__0)*JacobiSN(t, sin((1/2)*varphi__0))

(4)

Alternative using applyrule:
Using a dummy name like __d prevents runaway recursion under applyrule.

R := subsindets(lhs(eqn), And(name, Not(constant)), proc (nm) options operator, arrow; nm::anything end proc) = subs(JacobiSN = __d, rhs(eqn))

JacobiSN(z::anything, k::anything) = __d(z*k, 1/k)/k

(5)

orig = subs(__d = JacobiSN, C, applyrule(R, lhs(eqn)))

JacobiSN(sin((1/2)*varphi__0)*t, csc((1/2)*varphi__0)) = sin((1/2)*varphi__0)*JacobiSN(t, sin((1/2)*varphi__0))

(6)

restart


Now  a new example: Converting InverseJacobinAM to InverseJacobiSN

orig := InverseJacobiAM((1/2)*`ϕ__0`, sqrt(2)/sqrt(1-cos(`ϕ__0`)))

InverseJacobiAM((1/2)*varphi__0, 2^(1/2)/(1-cos(varphi__0))^(1/2))

(7)

eqn := convert(FunctionAdvisor(identities, InverseJacobiSN(z, k))[3], `global`)

InverseJacobiSN(z, k) = InverseJacobiAM(arcsin(z), k)

(8)

Use eval(eqn,1) for 1-level evaluation (to prevent its RHS from evaluating to an EllipticF call).

C := solve(`~`[`=`]([op(orig)], [op(rhs(eval(eqn, 1)))]), [k, z])[1]

[k = 2^(1/2)/(1-cos(varphi__0))^(1/2), z = sin((1/2)*varphi__0)]

(9)

orig = subs(C, lhs(eqn))

InverseJacobiAM((1/2)*varphi__0, 2^(1/2)/(1-cos(varphi__0))^(1/2)) = InverseJacobiSN(sin((1/2)*varphi__0), 2^(1/2)/(1-cos(varphi__0))^(1/2))

(10)

NULL

Download Applying_identities_from_FunctionAdivisor_ac.mw

First 10 11 12 13 14 15 16 Last Page 12 of 309