acer

28100 Reputation

29 Badges

17 years, 244 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

This issue is covered quite clearly on the Help page for topic if, in the section Nested Selection Statements. See also the Help page for topic printlevel.

I'll mention that the inner conditional code does indeed get executed. The effects you're seeing only relate to the display of the inner results.

These effects also cover such nesting involving do-loops.

A good place to start looking for details, when you have an issue with a particular command, would be the Help page for that command.

 

restart;

assume(y > 1);

expr[1] := exp(y*LambertW(ln(y)));
expr[2] := (ln(y)/LambertW(ln(y)))^y;
expr[3] := eval(x^(x^x), x = exp(LambertW(ln(y))));
expr[4] := eval(x^(x^x), x = ln(y)/LambertW(ln(y)));

exp(y*LambertW(ln(y)))

(ln(y)/LambertW(ln(y)))^y

(exp(LambertW(ln(y))))^((exp(LambertW(ln(y))))^(exp(LambertW(ln(y)))))

(ln(y)/LambertW(ln(y)))^((ln(y)/LambertW(ln(y)))^(ln(y)/LambertW(ln(y))))

simplify( expr[3] - expr[4] );

0

 

Another, with one extra step

 

simplify(combine( expr[3] - expr[1] ));

0

 

Progress of a kind

 

simplify( ln( expr[1]/expr[2] ) );

0

simplify( ln( combine( expr[3]/expr[2] ) ) );

0

Download LambW_simpl1.mw

You misspelled Distance as distance.

restart;

with(Student:-MultivariateCalculus):

A := [0, 0, 0]:
B := [c, 0, 0]:
C := [(-a^2 + b^2 + c^2)/(2*c),
      sqrt((a + b - c)*(a - b + c)*(-a + b + c)*(a + b + c))/(2*c), 0]:
S := [x, y, z]:

solve([Distance(S, A) = m, Distance(S, B) = n,
       Distance(S, C) = p], [x, y, z], explicit);

[[x = (1/2)*(c^2+m^2-n^2)/c, y = (1/2)*(a^2*c^2+a^2*m^2-a^2*n^2+b^2*c^2-b^2*m^2+b^2*n^2-c^4+c^2*m^2+c^2*n^2-2*c^2*p^2)/((-(a+b-c)*(a-b+c)*(a-b-c)*(a+b+c))^(1/2)*c), z = ((a^4-2*a^2*b^2-2*a^2*c^2+b^4-2*b^2*c^2+c^4)*(a^4*m^2+a^2*b^2*c^2-a^2*b^2*m^2-a^2*b^2*n^2-a^2*c^2*m^2-a^2*c^2*p^2+a^2*m^4-a^2*m^2*n^2-a^2*m^2*p^2+a^2*n^2*p^2+b^4*n^2-b^2*c^2*n^2-b^2*c^2*p^2-b^2*m^2*n^2+b^2*m^2*p^2+b^2*n^4-b^2*n^2*p^2+c^4*p^2+c^2*m^2*n^2-c^2*m^2*p^2-c^2*n^2*p^2+c^2*p^4))^(1/2)/(a^4-2*a^2*b^2-2*a^2*c^2+b^4-2*b^2*c^2+c^4)], [x = (1/2)*(c^2+m^2-n^2)/c, y = (1/2)*(a^2*c^2+a^2*m^2-a^2*n^2+b^2*c^2-b^2*m^2+b^2*n^2-c^4+c^2*m^2+c^2*n^2-2*c^2*p^2)/((-(a+b-c)*(a-b+c)*(a-b-c)*(a+b+c))^(1/2)*c), z = -((a^4-2*a^2*b^2-2*a^2*c^2+b^4-2*b^2*c^2+c^4)*(a^4*m^2+a^2*b^2*c^2-a^2*b^2*m^2-a^2*b^2*n^2-a^2*c^2*m^2-a^2*c^2*p^2+a^2*m^4-a^2*m^2*n^2-a^2*m^2*p^2+a^2*n^2*p^2+b^4*n^2-b^2*c^2*n^2-b^2*c^2*p^2-b^2*m^2*n^2+b^2*m^2*p^2+b^2*n^4-b^2*n^2*p^2+c^4*p^2+c^2*m^2*n^2-c^2*m^2*p^2-c^2*n^2*p^2+c^2*p^4))^(1/2)/(a^4-2*a^2*b^2-2*a^2*c^2+b^4-2*b^2*c^2+c^4)]]

Download distance_ex.mw

Is this the kind of effect you're after?

restart

with(ListTools):

Q := [15.59270850, 9.932905704, 5.445184045, 2.139179446, 0.];

[15.59270850, 9.932905704, 5.445184045, 2.139179446, 0.]

r := [5, 4, 3, 2, 1];

[5, 4, 3, 2, 1]

plot(r, Q);

revr, revQ := Reverse(r), Reverse(Q);

[1, 2, 3, 4, 5], [0., 2.139179446, 5.445184045, 9.932905704, 15.59270850]

plot(r, revQ, axis[1] = [tickmarks = [seq(r[i] = revr[i], i = 1 .. nops(r))]]);

Download plot_1_ac.mw

There are several variants on this methodology. I just gave one. (You don't necessarily need to construct revr. Instead you could refer to the reversed entries in the rhs of the tickmarks equation by indexing with a formula. And so on...)

I used Reverse after loading ListTools. Again, there are several other ways. Too many to mention. But the basic idea is to force the tickmarks.

ps. I gave one of the variants that is "simpler" because it relies on the special kind of r values you have. In fact for this special kind of r-values it could be done even more simply.

It's also possible to do it for more general r values (irregularly spaced, say), with a more exotic mapping. Let us know if you need that,

The idea behind that particular calling sequence is that you can efficiently re-use the created rtable (Array, Vector, etc). The relevant calls to Sample will populate the passed rtable, in-place.

This is more efficient than having Sample create new rtable containers each time, especially if you are going to do this many times.

restart

with(Statistics)

Define a random variable.

X := RandomVariable(Normal(0, 1))

Sample that random variable. We sample it 10 times and look at the output.

A := Sample(X, 10)

Vector[row](%id = 36893628369891418468)

The float rtable is defined with the sample number of elements as will be sampled.

tab1 := Array(1 .. 10, datatype = float[8])

Array(%id = 36893628369891408220)

The following acts in-place on tab1, populating it with new values.
Sample(X, tab1)

tab1

Array(%id = 36893628369891408220)

The following again acts in-place on tab1, populating it with new values.
Sample(X, tab1)

tab1

Array(%id = 36893628369891408220)

NULL

Download Sample_and_rtables.mw

You were failing to provide any knowledge of f to the attempts at computing c5,c6,c7.

I resolved that issue by calling dsolve on a coupled system -- once, for each set of parameter values. (Yes, you could dsolve for f alone, decoupled, and then reuse that result in the later dsolve calls for theta. But efficiency seems not a major concern in what you've attempted here. I'm just trying to keep it simpler for you to do -- it's just a judgement call, on what might be best for you.)

In at least one place you also had f instead of f(x). That's the kind of mistake you can make when you allow declare to make things visually unclear.

You had duplicates of most of the parameter information. I've cleaned all that up and made it more organized, which might help you keep track of which is what. Having twice as many solutions as necessary floating around, with numbering mismatches, seems a recipe for confusion.

Note that M only appears in eq1, and is multiplied by sin(alpha).
Hence M has no effect when sin(alpha) is taken as 0, which is the case for all your given parameter sets.

So I rearranged the parameter sets according to the value for cos(omega). And I added a legend. We can see that for your parameter sets it is the value of cos(omega) that is the key difference.

restart

kernelopts(version);

`Maple 18.02, X86 64 LINUX, Oct 20 2014, Build ID 991181`

with(PDETools, declare):

with(plots):

eq1 := diff(f(x), x, x, x) + 1/2*(1 - phi)^2.5*(1 - phi + phi*rho[s]/rho[fl])*(eta*cos(omega) + f(x)*sin(omega))*diff(f(x), x, x) + (1 - phi)^2.5*M*sin(alpha)^2*(1 - diff(f(x), x)) + (1 - phi)^2.5*(1 - phi + phi*`ρβ`[s]/`ρβ`[fl])*Gr[x]*`cosγ`*theta = 0;

diff(diff(diff(f(x), x), x), x)+(1/2)*(1-phi)^2.5*(1-phi+phi*rho[s]/rho[fl])*(eta*cos(omega)+f(x)*sin(omega))*(diff(diff(f(x), x), x))+(1-phi)^2.5*M*sin(alpha)^2*(1-(diff(f(x), x)))+(1-phi)^2.5*(1-phi+phi*`ρβ`[s]/`ρβ`[fl])*Gr[x]*`cosγ`*theta = 0

eq2 := K[nf]*diff(theta(x), x, x)/K[f] + Pr/2*(eta*cos(omega) + f(x)*sin(omega))*diff(theta(x), x) = 0;

K[nf]*(diff(diff(theta(x), x), x))/K[f]+(1/2)*Pr*(eta*cos(omega)+f(x)*sin(omega))*(diff(theta(x), x)) = 0

bcs := f(0) = 0, (D(f))(0) = 0, (D(f))(10) = 1;

f(0) = 0, (D(f))(0) = 0, (D(f))(10) = 1

theta(0) = 1, theta(10) = 0

a1 := [phi = .1, rho[s] = 5200, rho[fl] = 997.1, `ρβ`[s] = 6500, `ρβ`[fl] = 20939.1, M = 0, sin(alpha) = 0, cos(omega) = 1, sin(omega) = 0, Gr[x] = 0, Pr = 6.2, cos*gamma = 1, eta = 3, K[f] = .613, K[nf] = .6842]:

Note that M only appears in eq1, multiplied by sin(alpha).
Hence M has no effect when sin(alpha) is taken as 0.

c1 := dsolve({bcs, bcs1, subs(a1, eq1), subs(a1, eq2)}, numeric):

TFP := Typesetting:-Typeset(diff(f(x), x)):

display(p1, p2, p3, p4, p5, p6, p7, p8, thickness = 3, legendstyle = [location = right], size = [700, 450]);

NULL

Download IP-TEMP_ac.mw

You might wish to also try varying the sin(alpha) parameter, and then see the related effects of varying M.

The keen observer might notice that there is a lot in common amongst all those dsolve and odeplot calls. There is so much that could be generalized. But I've deliberately chosen not to wrap it all up in a single resuable procedure that could produce all the results.

There are a lot of members on this forum who attempt very similar problems. Several struggle with numeric dsolve & odeplot, and perhaps even with the DE concepts. I think that some members can learn more by doing each step themselves rather than use an abstracted do-it-all solution procedure.

The following was done using Maple 2023.0.

Where you see R subscripted by x it was entered as the keystrokes R__x with two underscores, and similarly for y and z subscripts.

restart;

`print/sin` := proc(t) ':-s'(t); end proc:
`print/cos` := proc(t) ':-c'(t); end proc:
(s,c) := sin,cos:

Typesetting:-Suppress(x(t));

Typesetting:-Settings(prime=t):
Typesetting:-Settings(typesetprime=true):
Typesetting:-Settings(useprime=true):

 

R__z := proc (A) options operator, arrow; `<,>`(`<|>`(c(A), s(A), 0), `<|>`(-s(A), c(A), 0), `<|>`(0, 0, 1)) end proc

R__x := proc (A) options operator, arrow; `<,>`(`<|>`(1, 0, 0), `<|>`(0, c(A), -s(A)), `<|>`(0, s(A), c(A))) end proc

R__y := proc (A) options operator, arrow; `<,>`(`<|>`(c(A), 0, s(A)), `<|>`(0, 1, 0), `<|>`(-s(A), 0, c(A))) end proc

 

R__z(psi)

Matrix(%id = 36893628812889702516)

 

simplify(R__x(phi).R__y(theta).R__z(psi))

Matrix(%id = 36893628812889688652)

diff(c(x)*s(x), t)

-(diff(x(t), t))*sin(x(t))^2+cos(x(t))^2*(diff(x(t), t))

diff(c(x)*s(x), t)

-(diff(x(t), t))*sin(x(t))^2+cos(x(t))^2*(diff(x(t), t))

diff(c(x)*s(x), x)

-(diff(x(t), t))*sin(x(t))^2+cos(x(t))^2*(diff(x(t), t))


In case it's not clear from the above, the outputs below do indeed
contain references to sin and cos proper. For instance,

c(x)*s(x)

cos(x(t))*sin(x(t))

`~`[has](%, [sin, cos])

[true, true]

combine(`%%`)

(1/2)*sin(2*x(t))

simplify(s(x)^2+c(x)^2)

1

Download sincos_ts.mw

The code in red above could be tucked away out of sight in a worksheet's Startup Code, accessible via the main menubar's Edit menu.

ps. I could mention that the first three lines of red code, which assigns to (s,c) and the print-extensions, could be replaced by alias, as Edgardo mentioned. My longstanding preference is not to use alias, which is why I didn't mention it earlier. The rest of the red code, the Typesetting calls, accomplish the rest of the aspects you mentioned or showed.

That lengthy result you obtained appears to have a "hidden" division-by-zero in it. I suspect that you might not be able to just simplify that away, given that form.

But the option method=trager to the int command seems to help here.

restart;

kernelopts(version);

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

ig[1] := 1/(z^2+sqrt(z^4+4*a*z^2)+4*a);

1/(z^2+(z^4+4*a*z^2)^(1/2)+4*a)

ans[1]:=int(ig[1],z,method=trager);

(1/4)*(z-1-(z^4+4*a*z^2)^(1/2)/z)/a

normal( diff(ans[1],z) - ig[1] );

0

ig[2] := -1/(z^2-sqrt(z^4+4*a*z^2)+4*a);

-1/(z^2-(z^4+4*a*z^2)^(1/2)+4*a)

ans[2]:=int(ig[2],z,method=trager);

(1/4)*(1-z-(z^4+4*a*z^2)^(1/2)/z)/a

normal( diff(ans[2],z) - ig[2] );

0

Download int_tr_ex.mw

I don't know all the details of the control flow by which available methods are attempted by default for indefinite integration. I'll submit this example as a bug report.

Consider this counterexample, where x=-1.

ee := (x^(3))^(1/3)

(x^3)^(1/3)

simplify(ee);

(x^3)^(1/3)

simplify(ee) assuming x>=0;

x

r := evala( eval(ee, x=-1) );

1/2+(1/2)*(-3)^(1/2)

simplify(r^3);

-1

simplify( ( -1 )^3 );

-1

simplify( ( 1/2+sqrt(-3)/2 )^3 );

-1

simplify( ( 1/2-sqrt(-3)/2 )^3 );

-1

S := [solve( x^3 = -1, x)];

[-1, 1/2-((1/2)*I)*3^(1/2), 1/2+((1/2)*I)*3^(1/2)]

plots:-display(
  plottools:-circle([0,0],1,color=blue),
  plots:-pointplot([Re,Im]~(S),
                   symbol=solidcircle, symbolsize=20,
                   color=red, size=[300,300]));

Download cbrt.mw

Perhaps a suitable time to review the documentation for the root (esp. 4th and 5th bullet points) and surd commands.

This particular example can be handled in one call to fsolve.

restart;

kernelopts(version);

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

R := RootOf(_Z*cos(_Z) - sqrt(sin(_Z)^2));

RootOf(_Z*cos(_Z)-(sin(_Z)^2)^(1/2))

arg := eval(op(1,R), _Z=x);

x*cos(x)-(sin(x)^2)^(1/2)

fsolve(arg, x=-6..6, maxsols=infinity);

-4.493409458, -2.028757838, 0., 4.913180439

fsolve(arg, x=-6..6, maxsols=infinity, method=NextZero);

-4.493409458, -2.028757839, 0., 4.913180439

Download rf_ex.mw

note: Given a numeric rootfinder, some example can be found that defeats it.

The contents of the Favorites palette are stored in a location on one's Operating System, somewhat similarly to how one's Maple GUI preferences are saved.

They are not saved inside an individual .mw file.

Also, Maple preferences are stored on the local computer, say, not in the cloud.

The contents of the palettes is part of the GUI itself, not the document.

Once you've created the plot using geometry:-draw, you could merge it with other kinds of plots in the usual way, ie. using plots:-display.

restart; with(geometry)

point(B, 2, 0)

B

form(B)

point2d

coordinates(B)

[2, 0]

The following uses geometry:-draw

draw(B)draw(B)

draw(B, color = blue, symbol = solidcircle)

NULL

Download plotpoint_ac.mw

You can replace those function calls (of t). You could do it using evalindets, and also with eval and a set/list of replacements.

This targets those particular names, but it'd also work if you had terms like sin(t), etc, leaving those alone.

problem_ach_ac.mw

restart;

with(LinearAlgebra):

n := Vector[row]([cos(theta(x, y, t)), sin(theta(x, y, t))]);

Vector[row](2, {(1) = cos(theta(x, y, t)), (2) = sin(theta(x, y, t))})

add(n[i]^2, i = 1 .. 2);

cos(theta(x, y, t))^2+sin(theta(x, y, t))^2

 

The next automatically simplifies to the previous...

 

add(n[i]*n[i], i = 1 .. 2);

cos(theta(x, y, t))^2+sin(theta(x, y, t))^2

 

If your Vector has just two entries, then isn't the next
simplest as well efficient?

 

n[1]^2+n[2]^2;

cos(theta(x, y, t))^2+sin(theta(x, y, t))^2

 

The next two work, but are unnecessarily complicated
because there's no great reason here to use Multiply(n[i],n[i]),
where Multiply is a LinearAlgebra command, since each n[i]
is just a scalar.

 

add(Multiply(n[i], n[i]), i = 1 .. 2);

cos(theta(x, y, t))^2+sin(theta(x, y, t))^2

sum('Multiply(n[i], n[i])', i = 1 .. 2)

cos(theta(x, y, t))^2+sin(theta(x, y, t))^2

 

Alternatives...

 

DotProduct(n,n,conjugate=false);

cos(theta(x, y, t))^2+sin(theta(x, y, t))^2

 

The next each unnecessarily produce a temporary
Vector as garbage for memory management.

 

n.n^%T;

cos(theta(x, y, t))^2+sin(theta(x, y, t))^2

add(n*~n);

cos(theta(x, y, t))^2+sin(theta(x, y, t))^2

add(n^~2);

cos(theta(x, y, t))^2+sin(theta(x, y, t))^2

Download vec_dot_add.mw

Is this the kind of thing you meant?

eq := diff(w(x), x, x) = F*(6*(-a^2/(2*L^2) + a^3/(3*L^3))*x + 2*a^2/L - a^3/L^2)/EI;

diff(diff(w(x), x), x) = F*(6*(-(1/2)*a^2/L^2+(1/3)*a^3/L^3)*x+2*a^2/L-a^3/L^2)/EI

(lhs=simplify@value@rhs)(map(Eval,eq,x=L));

Eval(diff(diff(w(x), x), x), x = L) = -F*a^2*(L-a)/(L^2*EI)

Download comp_map.mw

1 2 3 4 5 6 7 Last Page 3 of 292