## MaplePrimes Questions

Search Questions:

## GraphTheory, DrawGraph: "layout=interactive" doesn...

"What's new in Maple 2020" explain an exciting new option for DrawGraph: layout=interactive, that should allow you to move vertices in the plot. I tried this in the help page opened in a worksheet window and it works.

Unfortunately when I write in a new worksheet the command

with(GraphTheory): with(RandomGraph): G:=RandomGraph(10,25); DrawGraph(G,layout=interactive)

I get the error

"Error, invalid input: GraphTheory:-DrawGraph expects value for keyword parameter [style, layout] to be of type identical(none, bipartite, circle, default, fixed, grid, interactive, network, spectral, spring, spring[constant], tree, user, planar, random), but received plots:-interactive"

Could you help me? Thanks

## How did Maple obtain this solution that satisfies ...

This is really a math question. But I can't figure how Maple did it.

Maple solves the ODE with 2 initial conditions correctly.

But if I use the general solution, and setup the set 2 equations, and tell Maple to solve _C1 and _C2, it says there is no solutions. Which is correct.

I would really like to know how Maple then managed to solve for these initial conditions.  This is problem from text book

I know how to solve it by hand to obtain general solution. But do not know how find solution that satisfies the IC's. when pluggin the initial conditions, the resulting 2 equation have no solution.

restart;
ode:=2*diff(y(x),x\$2)=exp(y(x));
maple_general_sol:=dsolve(ode);
odetest(maple_general_sol,ode);
IC:=y(0)=0,D(y)(0)=1;
maple_sol_with_IC:=dsolve([ode,IC]);
odetest(maple_sol_with_IC,[ode,IC]);


The goal is to now take the general solution found by Maple above, and manually solve for _C1 and _C2:

eq1:=0=subs(x=0,rhs(maple_general_sol));
the_derivative:= diff(rhs(maple_general_sol),x):
eq2:=1=subs(x=0,the_derivative);


Two equations, two unknown. But using solve or PDEtools:-Solve produce no solution.

sol1:=solve([eq1,eq2],[_C1,_C2]);
sol2:=PDEtools:-Solve([eq1,eq2],[_C1,_C2]);


Looking at equation (1) above, we see that it is the same as

eq1:=1=(tan(_C2/(2*_C1))^2 + 1)/_C1^2;

Because 0=ln(Z) means Z=1. Using the above simpler equation now gives

eq1:=1=(tan(_C2/(2*_C1))^2 + 1)/_C1^2;
the_derivative:= diff(rhs(maple_general_sol),x):
eq2:=1=subs(x=0,the_derivative);
sol1:=solve([eq1,eq2],[_C1,_C2]);


We see that there is indeed no solution. Second equation above says _C1= tan(.). Let tan(.)=Z. Plugging this in first equation gives Z^2= (Z^1+1) which has no solution for Z since this says 0=1

So direct appliction of the initial conditions produces no solution. So how did Maple find the solution it obtained? I also tried using limits. But no luck. Book does not show how to obtain solution either.

Any ideas?

## solving sqrt(y)=tanh(x) for y...

When solving this by hand   sqrt(y)=tanh(x), I would square both sides to obtain  y=tanh(x)^2 as solution.

Maple does this when RHS is tan,cos,sin, but not when RHS is hyperbolic.

Why is that, and how to best tell Maple to give  the simple solution? Here is an example

restart;
eq:=sqrt(y)=tanh(x);
sol:=solve(eq,y);

Compare to Mathematica:

I can post-process Maple solution like this

restart;
eq:=sqrt(y)=tanh(x);
sol:=solve(eq,y);
sol:=convert(sol,trigh);
sol:=simplify(sol)

Which is tanh(x)^2.

But this is all too much work, since this is done in a program, and I do not know what specific convert to use at the time to try.

My question is, why does not maple simply solves   sqrt(y) = f(x)  giving     y=f(x)^2?  it works for generic function

restart;
eq:=sqrt(y)=f(x);
sol:=solve(eq,y);

it works for non-hyper trig functions also

restart;
eq:=sqrt(y)=tan(x);
sol:=solve(eq,y);

Is there a trick to make it work for hyperbolic functions also automatically?

ps. for now, to avoid all these issues, I am doing this

restart;
the_rhs:=tanh(x);
eq:=sqrt(y)=f;
sol:=solve(eq,y);
sol:=subs(f=the_rhs,sol);


Since I know that the RHS contains no y before hand. The above bypasses any issues Maple has with hyper trig functions.

## Show/hide input?...

Hello

Without any success, I've been trying to hide the input/code, such that only the output (moment and shear) diagram is shown. I've tried guides with Document Blocks method but all seem outdated, since they're referring to commands which don't seem to exist i.e. "collapse document block". I can't understand that there isn't some neat and user-friendly way to something as simple as show/hide the input, to make it more document-reader friendly? It seems the only way is to just hightlight the input and color it white, which isn't too viable long term.

I hope you can help, it would be alot of help to me and my classmates.
Kind regards and thanks for your time.

PS. Here's a picture of the input and diagram.

## Error on explore Command...

restart, with(plots);
startingTime := 1800;
interval := 10;
P(0) := 5.308;
P(t) = 5.308*M/(5.308 + (M - 5.308)*exp(-kMt));
5.308 M
P(t) = -----------------------------
5.308 + (M - 5.308) exp(-kMt)

diff(P(t), t) = kP(t)*(M - P(t));
d
--- P(t) = kP(t) (M - P(t))
dt

Explore(plot([P(t), [[0, 5.308], () .. (), [140, 131.7]]], t = 0 .. 0.140, P = 0 .. 140, style = [line, point], gridlines = true), parameters = [[M = M_0 .. M_1], [k = k_0 .. k_1]]);
Error, (in Explore) incorrect first argument [P(t), [[0, 5.308], () .. (), [140, 131.7]]]

## Complex ODE solutions using dsolve and fsolve....

I am currently trying to solve the following ODE using numerical methods:

+ [(z+ I*y)2/k12 -k22 +

Where the complex value (in this case, , has been written as z+Iy). I believe dsolve has capabilities for solving this as an initial value problem with complex values and thus to solve this as a boundary value problem I aim to use fsolve to find a zero other a function which is the (IVP solution) - (the non-initial boundary). This has worked very well for the case where y=0 however does not work for values of y>0, and it seems the problem is with fsolve. Any advice on how to deal with this problem, perhaps alternatives to fsolve?

## Table / table width...

Is there any possibility to modify column width within tables, so that they become equal?

## Problem in evaluating 2D improper integral ...

Dear Users!

I want to evaluate following integral (f[i]'s) for different values of rho as shown. But find some problem and can't find f[3], f[4], f[5] and f[6]. If the integral from direct way is hard to calculate please guide me how I can evaluate it using numerical integration?

restart; HAM := [1, 2, 3, 4, 5, 6]; U := y^6*sin(x); alpha := 1/3;

for i while i <= nops(HAM) do

rho := op(i, HAM);

f[i] := int(int(U/((x^rho-p^rho)^alpha*(y^rho-q^rho)^alpha), q = 0 .. y), p = 0 .. x)

end do

Special request to @acer @Carl Love @Kitonum @Preben Alsholm

## How to fasten this simulation?...

Hi,

I want to simulate a decision rule (let's say a production control strategy to fix the ideas) based on the outcomes of a binomial random variable.

One stage of this simulation involves operations which correspond to the NaiveProc described below. This procedure is a straightforward and rather naive translation in Maple of these operations.
It is given here to help you to understand what is to be done.

This coding being extremely slow, I implemented the required operations differently.
Given the fact that I'm only concerned by binomial samplings with outcomes 0 and 1, I basically replaced these samplings by three operations  U:=... , Got01:=... , Got0:= ... .
Each new implementation is about 200 times faster than the naive one.

My question is: Can we do still better?
For information the same simulation realized with R runs in less than 15s when REP = 10^8 (more than 100 times faster than what I'm capable to do with Maple)

 > restart:
 > with(Statistics):
 > # This is the naive coding of the problem # # It has the advantage to explain clearly (at least I hope so) what is to be done. NaiveProc := proc(REP, a, b, N)   local roll, rep, p, K, N0, N1:   roll := rand(a .. b);   N0   := 0:   N1   := 0:   for rep from 1 to REP do     p := roll();     K := Sample(Binomial(N, p), 1)[1]:     if K=0 then       N0 := N0+1:     elif K=1 then       N1 := N1+1:     end if:   end do:   N0, N1: end proc:      CodeTools:-Usage(NaiveProc(10^3, 0, 5e-4, 25000));
 memory used=78.92MiB, alloc change=68.00MiB, cpu time=1.21s, real time=6.30s, gc time=24.80ms
 (1)
 > # As the previous code is very slow I implemented several variants based on the fact # that I care only on values of K equal to 0 and 1 and that it is then useless to sample # a Binomial random variable to do this. # # Each of them is much faster than the naive coding... but can we even faster? # For comparison, the same simulation realized in R takes less than 15s to run with REP=10^8 pi := (n, p, k) -> binomial(n, k) * (1-p)^(n-k) * p^k; f1 := proc(REP, a, b, N)   local Q, P0, P1, P01, U, Got01, Got0, N01, N0, N1:   Q     := Sample(Uniform(a, b), REP)^+:   P0    := pi~(N, Q, 0):   P1    := pi~(N, Q, 1):   P01   := P0 + P1:   U     := Sample(Uniform(0, 1), REP)^+:   Got01 := Select(t -> is(t <= 0), U-P01):   Got0  := Select(t -> is(t <= 0), U-P0 );   N01   := numelems(Got01):   N0    := numelems(Got0):   N1    := N01-N0:   N0, N1; end proc: CodeTools:-Usage(f1(10^5, 0, 5e-4, 25000)); print(): f2 := proc(REP, a, b, N)   local Q, P0, P1, P01, U, Got01, Got0, N01, N0, N1:   Q     := Sample(Uniform(a, b), REP)^+:   P0    := pi~(N, Q, 0):   P1    := pi~(N, Q, 1):   P01   := P0 + P1:   U     := Sample(Uniform(0, 1), REP)^+:   Got01 := select[flatten](<=, U-P01, 0):   Got0  := select[flatten](<=, U-P0 , 0):   N01   := numelems(Got01):   N0    := numelems(Got0):   N1    := N01-N0:   N0, N1; end proc: CodeTools:-Usage(f2(10^5, 0, 5e-4, 25000)); print(): f3 := proc(REP, a, b, N)   local Q, P0, P1, P01, U, Got01, Got0, N01, N0, N1:   Q     := Sample(Uniform(a, b), REP)^+:   P0    := pi~(N, Q, 0):   P1    := pi~(N, Q, 1):   P01   := P0 + P1:   U     := Sample(Uniform(0, 1), REP)^+:   Got01 := Vector(REP, i -> if(U[i] <= P01[i], 1, 0)):   Got0  := Vector(REP, i -> if(U[i] <= P0 [i], 1, 0)):   N01   := add(Got01):   N0    := add(Got0):   N1    := N01-N0:   N0, N1; end proc: CodeTools:-Usage(f3(10^5, 0, 5e-4, 25000));
 memory used=376.83MiB, alloc change=296.77MiB, cpu time=4.12s, real time=4.03s, gc time=430.38ms
 memory used=173.26MiB, alloc change=0 bytes, cpu time=2.30s, real time=1.98s, gc time=461.22ms
 memory used=154.19MiB, alloc change=0 bytes, cpu time=2.28s, real time=2.01s, gc time=432.40ms
 (2)
 >
 >

## improvement to Latex. Removing extra \\ at end of ...

When Maple converts a matrix or a vector to Latex it uses latex array, which  is fine, but what it does is insert an exatra \\ at the end of the last row, just before the \end{array}

This causes problem for some software which reads the latex file. It causes the software to take this as empty row and inserts a blank row at the end.

Here is a small example

A:=Matrix([[1,2],[3,4]]);
Physics:-Latex(A);

\left[\begin{array}{cc}1 & 2 \\3 & 4 \\\end{array}\right]

Notice the extra \\  just before the \end{array} In Latex, this tells latex compiler to insert newline basically.

When opening the latex file using external software, which reads Latex and converts it to GUI, it show this

And now I have to go edit the latex by hand removing the extra \\ (inside the editor I can do global search and replace)

A better outout from Maple's Latex command would be the following

\left[\begin{array}{cc}1 & 2 \\3 & 4 \end{array}\right]

Even though both are valid Latex, the above is better.  I was wondering how hard it is to do this change.

All what the conversion needs to do is just check if the row in the matrix (or Vector) is the last one, and omit the extra \\ at the end of the last row. That is all.

I could ofcourse write code to try to parse this each time I call Latex and to remove \\ myself in the program, but it will be much easier if Maple automatically did this.

ps. if the Latex conversion source code could be made public, others could help make improvement to it for free, benefiting Maple and everyone using it. Maplesoft would still approve the changes before checkin, and retain the copy right of the source code ofcourse.

Maple 2020.1

## How to "remove output from worksheet" while it is ...

One of the known issues with Maple GUI (written in Java) is that it is slow.

When I run a long script, which prints few lines to the screen for each step (to help tell where it is during a long run), and if there are 20,000 steps to run which takes 2 days to finish), then the worksheet and I think all of Maple seem to slow down. May be due to GUI trying to flush output to worksheet which now has lots of output.

I noticed when I terminate the loop in the middle and then clear the worksheet from the output and start it again from where it stopped, then it runs/scrolls much faster initially untill the worksheet starts to fill up.

The problem is that one can no longer do Evaluate->Remove output from worksheet as worksheet is busy. This option becomes grayed out.

Is there a trick to bypass this limitation? It will be really nice to be able to clear output from worksheet while it is running.  I do not understand why a user can not do this now even if worksheet is running. In Mathematica for example, this is possible to clear the output while notebook is busy running. Not in Maple.

ps. I want to try to change my program to print output to external file instead to the worksheet and then can monitor the output progress using that file outside of Maple to see if this helps with performance.

This is until Maplesoft adds support to allow one to clear worksheet while it is busy.

Using Maple 2020.1 on windows. Using worksheet mode, not document mode.

## Multiply Quaternions...

Hello again,   I'm trying to write a procedure to multiply quaternions.   We know that they can be represented as a vector of length 4.   See Wikipedia.   My try  -

qaa=[8,4,6,2] and qab =[2,,4,6,8]
mult:=proc(a,b)

end proc;

maybe needs some looping or data from a table.

Regards,

Matt

## Margins in a Bode plot...

Hello All, is there a command/instruction that can tell me the phase margin, gain margin automatically after I have a bode plot, please?

## Units Standard / compare values with zero...

Units are a neverending story, here's a variant of a problem raised before.

How can i get the minimum of 2 values with Units[Standard] loaded, when one of them could be zero (this loosing its units)?

• https://www.mapleprimes.com/questions/229640-Units-Disappearing
• https://www.mapleprimes.com/questions/230165-Error-in-UnitsTestDimensions-Invalid
• https://www.mapleprimes.com/questions/230064-Compare-Similar-Units

 (1)

 (2)

 (3)

 (4)

 >
 >
 (1)
 >
 (2)
 >
 (3)
 >
 (4)
 >
 >