nm

11363 Reputation

20 Badges

13 years, 38 days

MaplePrimes Activity


These are questions asked by nm

colect(expr,y)  and collect(expr,y,factor) do not work on these.  The expression can be anything. No necessarily a polynomial in y.

I have as input an expression, which has y  in it, and I want to find if I can write it  as   y*(....)  of y^2*(...) or y^3*(...), etc...

Basically, I want to see if can be taken out as common term. Just like we do by hand. 

So, given expression as  y^2+y^3*sin(x)+3*x*y^5 then I want to see if it can be written as y^2*(1+y*sin(x)+3*x*y^3)

In the above y^2 was extracted as common term. I found that simplify sometimes work, but I can't depend on simplify, since it is not guranteed to work all the time. Here is an example where it worked

expr:=y^2+y^3*sin(x);
simplify(expr)

but if expression is this, then it did not extract out y^2

expr:=y^2+y^3*sin(x)+3*x*y^5;
simplify(expr)

I am doing this  all in code, without looking at the expression and decide what to do. 

I just know  is the name of the variable, and the expression will be a function of  and I just want to know if I can extract a common y^n  term out, so the result is y^n*g(y)

For example, for expr:=y^2+y^3*sin(x)+3*x; it will fail, since  I can't extract from all terms. In this case the result will be  y^2*(1+y*sin(x))+3*x  and this is not type(`*`). So it is ok for the method to fail, if it can not do it. I can always check the result to see if it failed or not.

Does Maple have build in method to do this? Or one has to program this? I wanted to ask first before if there is some hidden Maple function that can do this I did not see.

Sometimes math is easier to do by hand than using the computer :)

Maple 2020.2

Thanks.

edit: I also tried factor, but it does not work on everything. An example where it did not work

expr:=y^2+y^3*sin(x)+3*x*y^(7/2);
factor(expr);

It did not factor out y^2 because of y^(7/2) is not "integer, rational. numeric, or algebraic coefficients"? according to help.

Edit:

Thanks to all the answers. I used a combination of all of them to check if it can be factored or not, and now it is working for every example I tried it on. So if one method failed, I try the next method shown in the answers. 

 


 

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

 

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.

 

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.

First 100 101 102 103 104 105 106 Last Page 102 of 200