Maple Questions and Posts

These are Posts and Questions associated with the product, Maple

I have function that accept keyword argument. From this function, I need to pass this argument to another function using the same signature and using same name for the keyword. But it is not possible to do. 

Easier to explain with an example.   This is what I want to do

restart;
foo:=proc(n::integer,{ic::`=`:=[]})   
   post_process(n+1,'ic'=ic);
end proc;

post_process:=proc(n::integer,{ic::`=`:= []})
    print("in postprocess, n=",n, "ic=",ic);
end proc;

foo(3,'ic'=(y(0)=5))

Gives 

The problem is that when calling post_process(), using 'ic'=ic it does not work. Currently I have to change the keyword name as workaround, like this

restart;
foo:=proc(A::integer,{ic::`=`:=[]})
   print("in foo, A=",A, "ic=",ic);
   post_process(A,'new_ic'=ic);
end proc;

post_process:=proc(A::integer,{new_ic::`=`:= []})
    print("in postprocess, A=",A, "ic=",new_ic);
end proc;

foo(3,'ic'=(y(0)=5))

Which gives

Now it passed it. I would have liked to keep same keyword name ic in both function signatures instead of coming up with new name.

Is there a way to do that? 

This is not the only problem. The problem with this workaround, is that it does not work when the keyword argument is not passed to the first function. Because now it will use the default values of [].

Hence when calling the post_process() function, it fails due to type mismatch. This now gives an error

restart;
foo:=proc(A::integer,{ic::`=`:=[]})
   print("in foo, A=",A, "ic=",ic);
   post_process(A,'new_ic'=ic);
end proc;

post_process:=proc(A::integer,{new_ic::`=`:= []})
    print("in postprocess, A=",A, "ic=",new_ic);
end proc;

foo(3)

 

Error, (in foo) invalid input: post_process expects value for keyword parameter new_ic to be of type `=`, but received []

So the way I do this now, is to add an extra check each time, like this

restart;
foo:=proc(A::integer,{ic::`=`:=[]})
   if nargs = 2 then #is ic passed in?     
      post_process(A,'new_ic'=ic);
   else
      post_process(A);
   fi;
end proc;

post_process:=proc(A::integer,{new_ic::`=`:= []})
    print("in postprocess, A=",A, "ic=",new_ic);
end proc;

foo(3)# now it works

But in my actual code, I have more than one keyword argument, and I have to keep checking for correct number of arguments each time, to know which arggument to pass along. 

So far, I did not find an easy way around this.

Any suggestion how to do this better? passing keyword argument with default values? from one function to another without getting into these problems?

Maple 2020.2

 

Dear All 

I would like to calculate the five first terms of a  polynomial  sequence

I wrote in maple 

sum(x^r*(sum((-1)^s*binomial(r, s)*pochhammer((a+s+1)*d, n), s = 0 .. r))/factorial(r), r = 0 .. n), n = 0 .. 4);

I obtained 

0,0,0,0,0

which seems to be false

where is the problem 

Best regards 

This simple set of integrations works correctly and quickly in Maple 17 and other releases, but not in Maple 2020.

psi(x) := (-1)^v*(alpha*GAMMA(k-v)/v!/GAMMA(k-2*v-1)/GAMMA(k-2*v))^(1/2)*exp(-1/2*k*exp(-alpha*x))*                 (k*exp(-alpha*x))^(1/2*k-v-1/2)*LaguerreL(v,k-2*v-1,k/exp(alpha*x))/binomial(k-v-1,v);

Int(eval(%, [k=30.5, v=j, alpha=2.5])^2, x=-1..infinity) =
   seq(evalf[12](Int(eval(%, [k=30.5, v=j, alpha=2.5])^2, x=-1..infinity)), j=0..5);

Every time that I try this simple integration in Maple 2020 I receive a message "kernel connection lost".  Why???

Hi there,

what's wrong with this example:

ph_ex.mw

?

Thank you

Dear all

I have  Lie commutations for vectors e1, e2, e3, e4, e5, e6 as follow:

[e1, e3] = e3, [e1, e4] = e4, [e1, e5] = e5, [e1, e6] = e6, [e2, e3] = -e5, [e2, e4] = e6, [e3, e5] = e6

for which the command 

Query("Jacobi")

returns the false result, which means, the vectors are not closed under Jacobi's identity. How can I find vector triplets for which Jacobi's identity does not hold?

Please find Maple file.Jacobi_identity.mw

Hey everyone!
I have to solve this nonlinear system of equations . For small N (N=8), I tried to do it using solve but it is run forever. I have choosed \gamma to be equal to Pi/4.
test.mw

I tried to expand by the procedures series() and taylor(), but they compute to O(x15).

Hi

I have two sets of plots

1. plot([1 - 2*x, -0.6 - 2*x, -1 - 2*x], x = -1 .. 1)

2. smartplot[x, y](map('`=`', [31*y^2 + 0.19*x^2 + 0.34*x*y - 0.38*y - 0.22*x + 0.07, 0.31*y^2 + 0.19*x^2 + 0.34*x*y - 0.38*y - 0.22*x, 0.31*y^2 + 0.19*x^2 + 0.34*x*y - 0.38*y - 0.22*x + 0.02, 0.31*y^2 + 0.19*x^2 + 0.34*x*y - 0.38*y - 0.22*x + 0.07, 0.31*y^2 + 0.19*x^2 + 0.34*x*y - 0.38*y - 0.22*x + 0.11], 0))

How do i combine the two into one plot?

thanks!

R

 

Why Maple gives this error and is this a known issue?

restart;
pdsolve( [diff(u(x,t),t)=diff(u(x,t),x)*diff(u(x,t),x$2), u(x,0)=0],u(x,t))

Maple 2020.2 with Physics 893 on windows 10.

 

Dear all, 

I have a time-fractional PDE as follows.  ( denotes Caputo fractional derivative with respect to t) 

for alpha=1, this is a classical PDE and the exact solution is given as follows (in a book)

 

Question: 

 

1) for alpha=1, I want to find the L2 errors and L∞ errors in a table. 

2) for alpha=0.5, Can Maple find a solution (numeric or exact)?

 

MY TRY: (MAPLE 2020.2)

download the code.mw

restart:
with(plots):
PDE:=diff(y(x,t),t)=y(x,t)*diff(y(x,t),x$3)+y(x,t)*diff(y(x,t),x)+3*diff(y(x,t),x)*diff(y(x,t),x$2) ;


#c is an arbitratry constant
c:=4:
exact_sol:=(x,t)->-8*c/3*(cos ((x-c*t)/4))^2;

# I selected initial and boundary conditions as follows
IBC := { y(x,0)=exact_sol(x,0),y(0,t)=exact_sol(0,t),D[1](y)(0,t)=D[1](exact_sol)(0,t),y(1,t)=exact_sol(1,t)};
 	
numeric_sol := pdsolve(PDE,IBC,numeric);

num3d:=numeric_sol:-plot3d(t=0..1,x=0..1,axes=boxed,
            color=[0,0,y]);
exact3d:=plot3d(exact_sol(x,t),t=0..1,x=0..1,axes=boxed);
display(exact3d,num3d);

pdetest(y(x,t)=exact_sol(x,t),PDE,IBC);


Hi

I have a system of pde that it is solved with pdsolve procedure.

This procedure takes a few time, but when I need to do plots, especially 3d plot the software takes a lot of time (several hours).

How can I make plots faster?
Thanks.

The problem: to simplify the expression

for any negative  x  and  y .

Below we see that Maple copes with the task brilliantly (example 1). For example, it presents  sqrt(x*y)  as  sqrt(-x)*sqrt(-y)  and so on. But the same technique, applied only to the numerator of this expression does not give the desired presentation in the form of a square (example 2 and example 3).

restart;
# Example 1
A:=(x+y-2*sqrt(x*y))/(sqrt(-x)+sqrt(-y));
simplify(A) assuming negative;
factor(%,{sqrt(-x),sqrt(-y)});

                                         

restart;
# Example 2
B:=x+y-2*sqrt(x*y);
simplify(B) assuming negative;
factor(%,{sqrt(-x),sqrt(-y)});

                                           

 

restart;
# Example 3
B:=x+y-2*sqrt(x*y);
R:=simplify(B) assuming positive;
combine(R) assuming positive;
factor(R,{sqrt(x),sqrt(y)});

                                                   

Two questions:

1. Does anyone know the reasons for this behavior.

2. Does anyone know an easy way to simplify in examples 2 and 3 (without  substitutions  like  x=+-u^2  and  y=+-v^2 and so on,  of course)

 

Download sqrt.mw

 

I am using solution given in How-To-Make-Sort-Work-With-Alias which works well.

But on more testing, I found that Latex drops the constant of integration after applying the above solution, when this constant shows at the front of the rhs of the expression.

I have no idea why this happens. I will post two examples. The first shows the problem with the Latex generated, showing the constant is missing from the Latex. The second example is where I moved the constant  to inside the expression keeping everything else the same, and now the Latex generated no longer drops it. 

This is serious problem, since now my solutions are losing constant of integration in Latex display depending on where it is located.

example 1

restart;
assign(seq(`print/_C`||k, k=0..10) = seq(c[k], k=0..10)):
S:=[seq(_C||k = _C||k(), k=0..10)]:

sol:= y(x) = _C1/cosh(x)+(cosh(x)^2+cosh(x)*sinh(x)+x)/cosh(x);
sol:=subs(S, sort(sol));

Now watch what happens to the Latex of the above

Latex(sol)

y \! \left(x \right) = 
\frac{1}{\cosh \! \left(x \right)}+\frac{\cosh^{2}x +\cosh \! \left(x \right) \sinh \! \left(x \right)+x}{\cosh \! \left(x \right)}

Which compiles to 

\documentclass[11pt]{article}
\usepackage{amsmath}
\begin{document}
\[
y \! \left(x \right) = \frac{1}{\cosh \! \left(x \right)}+\frac{\cosh^{2}x +\cosh \! \left(x \right) \sinh \! \left(x \right)+x}{\cosh \! \left(x \right)}
\]
\end{document}

Now will do the same, but move the constant to the second term. Now it shows up

example 2

restart;
assign(seq(`print/_C`||k, k=0..10) = seq(c[k], k=0..10)):
S:=[seq(_C||k = _C||k(), k=0..10)]:

sol:= y(x) = 1/cosh(x)+ _C1*(cosh(x)^2+cosh(x)*sinh(x)+x)/cosh(x);
sol:=subs(S, sort(sol));

Now generate the latex

Latex(sol)

y \! \left(x \right) = 
\frac{\left(\cosh^{2}x +\cosh \! \left(x \right) \sinh \! \left(x \right)+x \right) c_{1}}{\cosh \! \left(x \right)}+\frac{1}{\cosh \! \left(x \right)}

Which compiles to 

\documentclass[11pt]{article}
\usepackage{amsmath}
\begin{document}
\[
y \! \left(x \right) = 
\frac{\left(\cosh^{2}x +\cosh \! \left(x \right) \sinh \! \left(x \right)+x \right) c_{1}}{\cosh \! \left(x \right)}+\frac{1}{\cosh \! \left(x \right)}
\] 
\end{document}

I am using 2020.2 with Physics 893 on windows 10.

Any idea what is going on? And why this happens when constant is at front only?

ps. the Purpose of using the solution in the above link, is to be able to use c[1] instead of _C1 in the final latex, and also have these constants show at front (this is what sort does) which makes the final expression better looking).

Thank you

Edit

In the debugger, going over Latex() function, I found where the problem happen.  There is a call near line 20 which does this

              Latex:-Print(e,':-executeprintroutines');

Where is the input. Which in this case is the sol expression passed to the Latex command.

Removing ':-executeprintroutines' from the above call, the constant remain there and is not lost.

It seems assign(seq(`print/_C`||k, k=0..10) = seq(c[k], k=0..10)): used before the call to Latex is confusing things.

Here is illustration:

restart;
assign(seq(`print/_C`||k, k=0..10) = seq(c[k], k=0..10)):
S:=[seq(_C||k = _C||k(), k=0..10)]:
sol:= y(x) = _C1/cosh(x)+(cosh(x)^2+cosh(x)*sinh(x)+x)/cosh(x);
sol:=subs(S, sort(sol));


Latex:-Print(sol,':-executeprintroutines');
Latex:-Print(sol);

And the output of the last 2 commands is

This shows when using ':-executeprintroutines' the constant is lost. I do not know what ':-executeprintroutines' does or where it is defined to try to modify it.

There is a problem here somewhere. Maple hangs on this ODE. Looking at trace, it hangs in trying homogeneous G

is this a known defect and could be resolved?

restart;
infolevel[dsolve]:=4;
dsolve(x^3*diff(y(x),x)^2+x*diff(y(x),x)-y(x) = 0,y(x))

... hangs

Adding different timelimits, it looks like the function gcd/LinZip is the culprit. Since it always seems to be there each time the timelimit expires (if it expires, sometimes it hangs even with timelimit).  But I noticed the above function many times in timelimit. So it seems the above functions is what causes many of the hangs I see.

Using `Lie` method, dsolved finishes almost instantly.

restart;
dsolve(x^3*diff(y(x),x)^2+x*diff(y(x),x)-y(x) = 0,y(x),'Lie')

This is on Maple 2020.2

It would be useful to know the cause of the hang, as fixing it could solve other problems.

I also notice that on Maple 2019.2 the first example above finished very fast also. So this is an issue that was introduced in Maple 2020.

All on windows 10.

I am having hard time controlling my Latex:-Settings now. The issue is that I do not know what each setting accepts as values, and what each value does.  The way I've been doing it is by collecting what useful ones posted in this forum, and what it does and save it in my cheat sheet. 

But now I see I need to change something, but not sure to what.

Is there a way to find what all the settings are, and description  of what each does and accepts as values? For example, 

            powersoftrigonometricfunctions

Accepts mixed and computernotation  But where are these described in terms of what they do? does it accept anything else?  Notice that ?leavespaceafterfunctionname does not show anything.

If I do 

restart;
Latex:-Settings()

it gives

[cacheresults = true, invisibletimes = " ", leavespaceafterfunctionname = false, 
powersoftrigonometricfunctions = mixed, spaceaftersqrt = true, usecolor = true, 
useimaginaryunit = I, useinputlineprompt = true, userestrictedtypesetting = false, 
usespecialfunctionrules = true, usetypesettingcurrentsettings = false]

But do not know how to obtain full description and possible value of each to see what they mean and do.

I think having Latex:-Settings() is a great idea, as it allows maximum flexibility for user to configure how they want the Latex output to be, but as more options are added, this type of information become more important to know and to keep track of.

I am using 2020.2 and Physics version 893

 

First 337 338 339 340 341 342 343 Last Page 339 of 2097