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

You can use the so-called 2-argument calling sequence of the eval command, to evaluate the expression at specific values for names upon which it depends.

If you are already have the lists of values then you can do it all programmatically, instead of typing out all those individual equations. That'd let you do it more easily if you have further collections of values to use.

expr := (`ϵ__1`*exp(`ζ__1`*phi)+`ϵ__2`*exp(zeta__2*phi))/(`ϵ__3`*exp(`ζ__3`*phi)+`ϵ__4`*exp(`ζ__4`*phi))

eval(expr, [`ϵ__1` = 1, `ϵ__2` = 1, `ϵ__3` = 1, `ϵ__4` = 0, `ζ__1` = 0, `ζ__2` = 1, `ζ__3` = -2, `ζ__4` = 0])

(1+exp(phi))/exp(-2*phi)

vars1 := [`ϵ__1`, `ϵ__2`, `ϵ__3`, `ϵ__4`]; vars2 := [`ζ__1`, `ζ__2`, `ζ__3`, `ζ__4`]

L1, L2 := [1, 1, 1, 0], [0, 1, -2, 0]

eval(expr, [Equate(vars1, L1)[], Equate(vars2, L2)[]])

(1+exp(phi))/exp(-2*phi)

Download eval_ex_1.mw

note. You could also construct a reusable procedure to do the substitutions, by using unapply on the expression (w.r.t. all those names). That doesn't really seem better to me, especially if you're only going to use it once.

expr := (`ϵ__1`*exp(`ζ__1`*phi)+`ϵ__2`*exp(zeta__2*phi))/(`ϵ__3`*exp(`ζ__3`*phi)+`ϵ__4`*exp(`ζ__4`*phi))

F := unapply(expr, `ϵ__1`, `ϵ__2`, `ϵ__3`, `ϵ__4`, `ζ__1`, `ζ__2`, `ζ__3`, `ζ__4`)

F(1, 1, 1, 0, 0, 1, -2, 0)

(1+exp(phi))/exp(-2*phi)

Download eval_ex_2.mw

Hopefully I haven't misunderstood all your goals.

I did the first attempt (with a finer resolution of points) in two ways: one like your original, and one more efficient that stops (for each X value) when it finds the first W value that succeeds.

At the end I also threw in some stuff with going straight for a curve (finding the first W value of equality, for the given range). And also a bit with some extended ranges. Might be useful; I'm not sure. I don't know what the end-point -1.7 might mean to you, as a restriction...

restart;

Digits:=15;

15

Lambda[0]:=2/(1*(5+3*w))

2/(5+3*w)

h:=1*a^(-3/2*(1+w))

a^(-3/2-(3/2)*w)

L:=simplify(int(1/h,a))

2*a^(5/2+(3/2)*w)/(5+3*w)

F:=1/(sqrt(2*Pi)*tau)*exp(-(lambda-Lambda[0])^2/(2*tau^2))

(1/2)*2^(1/2)*exp(-(1/2)*(lambda-2/(5+3*w))^2/tau^2)/(Pi^(1/2)*tau)

F2:=simplify(subs(lambda=L,F)*diff(h,a)*1/a)

-(3/4)*a^(-7/2-(3/2)*w)*2^(1/2)*(1+w)*exp(-2*(a^(5/2+(3/2)*w)-1)^2/((5+3*w)^2*tau^2))/(tau*Pi^(1/2))

F3:=isolate(Lambda[0]-tau=subs(a=A,L),tau)

tau = -2*A^(5/2+(3/2)*w)/(5+3*w)+2/(5+3*w)

F4:=Int(simplify(combine(subs(F3,F2))),a=0.01..10,method=_d01ajc)
     assuming A>0.5, A<1, a>0.01, a<10, w>-1.7, w<-1;

Int((3/8)*a^(-7/2-(3/2)*w)*2^(1/2)*(1+w)*exp(-(1/2)*(a^(5/2+(3/2)*w)-1)^2/(A^(5/2+(3/2)*w)-1)^2)*(5+3*w)/(Pi^(1/2)*(A^(5/2+(3/2)*w)-1)), a = 0.1e-1 .. 10, method = _d01ajc)

valid:= proc(n,b,w,A)
if n<b then #print("ok, n,b",n,b,w,A);
return true:
else
return false
end if:
end proc:

X:=[seq(A,A=0.5..0.99,0.01)]:

nops(X)

50

W:=[seq(w,w=-1.7..-1,0.01)]:

nops(W);

71

forget(evalf); forget(`evalf/int`):
st:=time[real]():
S1:=[seq(ListTools:-Search(true,[seq(valid(evalf(F4),1/(8*rhs(F3)^2),w,A),
                                                       w=W)]),
                           A=X)]:
S1:=eval(S1,0=NULL);
time[real]()-st;

[68, 68, 68, 67, 66, 65, 63, 57, 46, 41, 38, 35, 32, 29, 26, 23, 20, 17, 13, 10, 6, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]

2.873

forget(evalf); forget(`evalf/int`):
st:=time[real]():
T := 'T':
for ii from 1 to nops(X) do
  for jj from 1 to nops(W) do
    #print(ii,jj,W[jj],X[ii]);
    if evalf(eval(F4<1/(8*rhs(F3)^2),[w=W[jj],A=X[ii]])) then
      T[ii] := jj;
      #print([X[ii],W[jj]]);
      # value found for this A, bail out of the inner loop
      jj:=nops(W); next;
    end if;
  end do;
end do;
S1alt:=convert(T,list);
time[real]()-st;

[68, 68, 68, 67, 66, 65, 63, 57, 46, 41, 38, 35, 32, 29, 26, 23, 20, 17, 13, 10, 6, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]

.887

Y1:=[seq(W[S1[i]],i=1..nops(S1))]:

P1:=plots:-pointplot([X,Y1],view=[0.5..1,-2..0],style=pointline,
              symbol=solidcircle,symbolsize=10,color=red,size=[500,300])

Y1alt:=[seq(W[S1alt[i]],i=1..nops(S1alt))]:

P1:=plots:-pointplot([X,Y1alt],view=[0.5..1,-2..0],style=pointline,
              symbol=solidcircle,symbolsize=10,color=red,size=[500,300])

Digits:=10:
plots:-display(
  plot(-1.7,0.5..1,linestyle=dot,color=gray),
plot(Xval->RootFinding:-NextZero(unapply('Re@evalf'(eval(-F4+1/(8*rhs(F3)^2),A=Xval)),w),-2.7,
                                 maxdistance=2.7,guardDigits=1, signchange=false, abstol=1e-5),
     0.5 .. 0.8, adaptive=true, view=[0.5..1,-2..0], size=[500,300])
);

unapply('evalf'(eval(-F4+1/(8*rhs(F3)^2),A=0.95)),w):
plot([Re@%,Im@%],-5..-1, size=[500,300]);

 

Download NumericScale_ac.mw

By "Gauss-Jordan form" do you mean reduced row echelon form, as produced by Gauss-Jordan elimination?

If so, then consider computing the r.r.e.f. of the Matrix augmented by the identity-matrix. The row operations that take the Matrix to its r.r.e.f. would then also be done to the identity matrix.

Below, if B the r.r.e.f. of M turns out to be the identity-matrix, then A (the result of the same row operations, but done to the identity matrix) is the inverse of M.

See also the subsection "Finding the inverse of a matrix" of this page on Gaussian elimination.

restart;
randomize():
with(LinearAlgebra):

n := 3:
M := RandomMatrix(n,generator=-3..3);

Matrix(3, 3, {(1, 1) = -2, (1, 2) = -1, (1, 3) = 1, (2, 1) = -1, (2, 2) = -3, (2, 3) = 1, (3, 1) = -3, (3, 2) = -3, (3, 3) = -3})

(B,A):=(a->(a[..,..n],
            a[..,n+1..]))(ReducedRowEchelonForm(<M|IdentityMatrix(n)>));

B, A := Matrix(3, 3, {(1, 1) = 1, (1, 2) = 0, (1, 3) = 0, (2, 1) = 0, (2, 2) = 1, (2, 3) = 0, (3, 1) = 0, (3, 2) = 0, (3, 3) = 1}), Matrix(3, 3, {(1, 1) = -1/2, (1, 2) = 1/4, (1, 3) = -1/12, (2, 1) = 1/4, (2, 2) = -3/8, (2, 3) = -1/24, (3, 1) = 1/4, (3, 2) = 1/8, (3, 3) = -5/24})

A.M - B;

Matrix(3, 3, {(1, 1) = 0, (1, 2) = 0, (1, 3) = 0, (2, 1) = 0, (2, 2) = 0, (2, 3) = 0, (3, 1) = 0, (3, 2) = 0, (3, 3) = 0})

M^(-1);

Matrix(3, 3, {(1, 1) = -1/2, (1, 2) = 1/4, (1, 3) = -1/12, (2, 1) = 1/4, (2, 2) = -3/8, (2, 3) = -1/24, (3, 1) = 1/4, (3, 2) = 1/8, (3, 3) = -5/24})

M := RandomMatrix(n,generator=-3..3);

Matrix(3, 3, {(1, 1) = -3, (1, 2) = -1, (1, 3) = 1, (2, 1) = 0, (2, 2) = -2, (2, 3) = -1, (3, 1) = -1, (3, 2) = 1, (3, 3) = 1})

(B,A):=(a->(a[..,..n],
            a[..,n+1..]))(ReducedRowEchelonForm(<M|IdentityMatrix(n)>));

B, A := Matrix(3, 3, {(1, 1) = 1, (1, 2) = 0, (1, 3) = -1/2, (2, 1) = 0, (2, 2) = 1, (2, 3) = 1/2, (3, 1) = 0, (3, 2) = 0, (3, 3) = 0}), Matrix(3, 3, {(1, 1) = 0, (1, 2) = -1/2, (1, 3) = -1, (2, 1) = 0, (2, 2) = -1/2, (2, 3) = 0, (3, 1) = 1, (3, 2) = -2, (3, 3) = -3})

A.M - B;

Matrix(3, 3, {(1, 1) = 0, (1, 2) = 0, (1, 3) = 0, (2, 1) = 0, (2, 2) = 0, (2, 3) = 0, (3, 1) = 0, (3, 2) = 0, (3, 3) = 0})

M^(-1);

Error, (in rtable/Power) singular matrix

Download some_la.mw

For the case of a plot output you could select (mouse-pointer) and copy the manipulated plot, and then paste in a new exec-group (say), below. Then comment out the input line.

More generally, you could do the following:
  - ensure that the menubar's "View" has "Markers" toggled on.
  - use the left Marker-border to right-click and select the whole exec-group
  - use the left Marker-border to right-click and put an annotation on that exec-group (For me, this gives it a light purple background)
  - comment out the input line
This can be later undone by removing the annotation.

For me these effects side-step the menubar's "Remove Output from Worksheet", or !!! "Execute the entire worksheet".  See attached for example of each, made with Maple 2023.0.
anno_ex.mw

I believe that these are (mostly all) different students.

When I see the same question I delete it as a duplicate.

I believe that it could reduce this behavior if members stopped answering them separately.

restart;

kernelopts(version);

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

z:=-a*exp(-I*b):

Phi:=simplify(evalc(argument(z)));

arctan(a*sin(b), -a*cos(b))

plot3d([Phi,-b], a=-7..7, b=-2*Pi..2*Pi,
       color=[blue,red], grid=[51,51], axis[3]=[tickmarks=piticks]);

simplify(evalc(argument(z))) assuming a<0, b>=-Pi, b<-Pi/2;

-b

simplify(evalc(argument(z))) assuming a<0, b>=-Pi/2, b<=Pi/2;

-b

simplify(evalc(argument(z))) assuming a<0, b>=Pi/2, b<Pi;

-b

Download arg_ex0.mw

Collapsing those conditions seems not so straightforward.

Are you hoping for an effect that looks something like this?

plots:-polarplot(tan(theta)*sec(theta), theta = 0 .. 2*Pi,
                 style=point, adaptive=false, numpoints=10^4,
                 axiscoordinates=cartesian,
                 view=[-100..100, 0..10^4])

Download pl1.mw

 

plots:-polarplot(tan(theta)*sec(theta), theta = 0 .. Pi,
                 axiscoordinates=cartesian,
                 view=[-100..100, 0..10^4])

Download pl2.mw

By changing the difference of the pair of sin&cos calls into a product we can give solve a helping hand.

Solving the product is, naturally, quite easy.

ee := trigsubs('cos'(3*x - Pi/12) - cos(2*x + Pi/7))

[-2*sin((5/2)*x+(5/168)*Pi)*sin((1/2)*x-(19/168)*Pi)]

solve(ee, allsolutions);
 

{x = (19/84)*Pi+2*Pi*_Z4}, {x = -(1/84)*Pi+(2/5)*Pi*_Z3}

Download sc_solve_2023_2.mw

 

Here's a more programmatic variant of that, but without having to manually enter a cos call within uneval quotes,

restart;

ee := cos(3*x - Pi/12) = cos(2*x + Pi/7):

ff := trigsubs( convert( (lhs-rhs)(ee), sin ) );

[2*cos((5/2)*x+(89/168)*Pi)*sin((1/2)*x-(19/168)*Pi)]

solve(ff, allsolutions);

{x = (19/84)*Pi+2*Pi*_Z2}, {x = -(1/84)*Pi+(2/5)*Pi*_Z1}

Download sc_solve_2023_3.mw


And here's something with another kind of intermediate conversion, but also with a result more readily understandable than your straight solve attempt (which is large, with RootOf's).

restart;

kernelopts(version);

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

ee := cos(3*x - Pi/12) = cos(2*x + Pi/7);

sin(3*x+(5/12)*Pi) = cos(2*x+(1/7)*Pi)

simplify([solve(convert(ee,exp),allsolutions)]);

[Pi*(2*_Z2+19/84), Pi*(2*_Z1-1/84), Pi*(2*_Z1+163/420), Pi*(2*_Z1+331/420), Pi*(2*_Z1-341/420), Pi*(2*_Z1-173/420)]

Download sc_solve_2023_1.mw

 

I will submit a couple of bug reports about various weaknesses discovered here in solve and trigsubs. That is: the original unwieldy result from solve, and trigsubs not knowing how to handle some variants on the sum/difference forms.

It seems that the (SSL) certificate for this site had expired, preventing https access. (http access was still possible I think.)

It may have been fixed.

In your second question you are missing the multiplication between 10 and Unit(m/s).

As you have it, in 1D plaintext input,
  10Unit(m/s)
it is not valid Maple syntax.

In pretty-printed 2D Output the multiplication is represented implicitly by a space.

with(Units:-Simple)

solve((24.5*Unit('kPa')*250)*Unit('mL')/((8.3145*Unit('J'/('K'*'mol'))*292.5)*Unit('K')) = n)

0.2518512351e-2*Units:-Unit(mol)

NULL

0.1e-2*(24.5*Unit('kPa')*10^3*Unit('Pa'/'kPa')*250)*Unit('mL')*Unit('L'/'mL')*10^(-3)*Unit('m'^3/'L')/((8.3145*Unit('J'/('K'*'mol'))*292.5)*Unit('K'))

0.2518512351e-2*Units:-Unit(mol)

Why is there a difference between the two results above?

 

Second question: I use a shortcut when I want to write units (on my Mac it is CMD+Shift+u). I just found out while writing this worksheet that for Maple input the shortcut does produce something but executing a line where this was used generates an error as can be seen below.

 

10*Unit('m'/'s')

10*Units:-Unit(m/s)

10*Unit(m/s)

10*Units:-Unit(m/s)

 

NULL

Download Units_ac.mw

Performing simplify-with-side-relations does a kind of normal form operation in a polynomial sense.

It doesn't perform every other kind of simplify action. This is documented on the Help page with Topic simplify,details.

In that page's Options section it says,
  "Invokes only the simplification procedures specified by the additional names."
followed by a list of names. The word "siderels" is one of those names listed (and which is a cross-reference I gave at top). Yes, "siderels" itself is not an actual option name proper, but it's listed there since its relevent option names are governed by that same principle.

For example,

simplify(exp(2)*exp(4)-exp(6));

0

simplify(exp(2)*exp(4)-exp(6), {});

exp(2)*exp(4)-exp(6)

simplify(sin(x)^2+cos(x)^2-1);

0

simplify(sin(x)^2+cos(x)^2-1,{});

sin(x)^2+cos(x)^2-1

simplify(exp(2)*exp(4)-exp(6), trig);

exp(2)*exp(4)-exp(6)

simplify(sin(x)^2+cos(x)^2-1, exp);

sin(x)^2+cos(x)^2-1

Download simp_siderels_1.mw

Apparently the two-argument variant of EllipticE gets covered under EnableTypesetRule with the token,
     "EllipticE2"

So, that case gets covered for me (M2023.0) if I instead do it as,

   Typesetting:-EnableTypesetRule({"EllipticE", "EllipticE2", "EllipticF", "EllipticK"})

You can also enable it for all the special functions about which it knows, with,

   Typesetting:-EnableTypesetRule(Typesetting:-SpecialFunctionRules)

I don't know why the 2-argument E and F are not rendered in bold.

I will submit a bug report against the lack of bold, and the lack of documentation on the Help page about the multi-argument variants.

ps. I also see that "EllipticF" is adequate to cover its (sole!) 2-argument case. The naming scheme thus seems a bit unhelpful. But there's enough documented detail to see that this aspect is key. (It's also seen in the Typesetting:-RuleAssistant's popup details...)

The problem appears to lie in the new (Maple 2022, default) adaptive=geometric algorithm.

If you force the (older default) adaptive=true then the whole region gets plotted.

restart;

T:=(x,beta)->(1+sin(sqrt(x-1)*beta)^2/(4*x*(x-1)))^(-1):

plot(T(x,4), x=0..5, adaptive=true,
     labels=[E/V[0],T], labelfont=[times,20],
     axesfont=[times,20],thickness=3,view=[0..5,0..1])

Download PlotIssue_ac.mw

I will submit a bug report against this example.

note: For this example it happens you might also use adaptive=false, though in general (other examples) that will not attempt to refine the curve near portions with high curvature or save space in portions that need fewer points.

See also the adaptive Help page.

Here's a kludge to make the datasetlabels=contents result look a bit better.

This is customized for this example, and won't handle many more elements without further adjustment/tweaks and/or reduction of font size. To be more general it would have to do more work, eg. also act according to where the "content" strings occurred, etc.

restart;

Q:=Statistics:-VennDiagram(isprime, issqr, x -> irem(x, 3) = 0, universe = {$ (1 .. 100)},
                           legend = ["Prime", "Square", "Multiple of 3"],
                           datasetlabels=contents,
                           font=[Times,12], size=[800,900], scaling=unconstrained):

R:=map(proc(s) local i,L;
        L := [ListTools:-LengthSplit([parse(s)[]],8)];
        s=`if`(nops(L)=0,s,
               cat("\n\n{",convert(L[1],string)[2..-2],
                       seq(["\n ",convert(L[i],string)[2..-2]][],
                           i=2..nops(L)),"}\n"));
       end proc,indets(indets(Q,specfunc(TEXT)),string)):

subs(R,Q);

Download DigVenn_ac.mw

Here are two simple alternatives, for your example. I'd generally favour the former over the latter.

restart;
decisions := "accept", "reject":
T := 2:

`if`(1 > T, decisions[1], decisions[2]);

               "reject"

eval('`if`'(1 > T, decisions));

               "reject"

You asked why your problematic situation occurs. The `if` command has special evaluation rules, in which its arguments are not fully evaluated up front in the usual way.

One common motivating example for this design is that NULL can be passed (including the case of NULL as a 2nd argument), with the separate arguments recognized. If the argument sequence were flattened in the usual way during up-front evaluation then the following example would not work as intended.

restart;

map(u->`if`(u>2, NULL, u), [-3,7,1,9]);

          [-3, 1]

Here is another example, in which the desired behaviour also relies on the non-flattening of the argument sequence (possible by virtue of the special evaluation rules). Under usual evaluation rules the following would behave like a function call with four arguments.

restart;
p1:= A,B:
p2:=C:

`if`(3>2, p1, p2);

             A, B

Note that a workaround construction like,
   eval('`if`'( ... ))
would break the functionality of the first two examples I've given, because the forced full evaluation flattens the argument sequence.

The behaviour is somewhat similar during the initial construction where you called piecewise, which also has special evaluation rules.

note. The ifelse command also has special evaluation rules, and ought to be mentioned on the cited ?spec_eval_rules Help page.

First 12 13 14 15 16 17 18 Last Page 14 of 309