nm

8552 Reputation

19 Badges

12 years, 352 days

MaplePrimes Activity


These are replies submitted by nm

@lcz 

At the beginning I thought there would be a simple and fast function. Just like mathematica. 

The first Mathematica code from the link you have

Table[a[[i]], {i, 1, le, 2}]

is really the same as the Maple code 

seq(ls[i],i=1..nops(ls),2)

In Mathematica, Table[] is like seq() in Maple.  Notice, you asked for odd and even. The question you linked to asked for just odd. So may be that why the Maple code I posted looked a little longer.

@vv 

"It seems that there is an easy method."

yes. That is easier. This is the method that I wrote down yesterday below.  

@mmcdara 

Thanks for the idea. But it does not work for all case. For example given this

It does not do it:

restart:
expr:=y^2+y^3*sin(x)+3*x*y^(7/2);
convert(expr, horner, y)

But when doing this by hand, we see it can be factored as

proof:

should_be:=y^2*(1+y*sin(x)+3*x*y^(3/2));
expand( should_be )

@Parham2016 

Rubi is a Mathematica package. There is no port for it for Maple at this time. So you need Mathematica to run the above.

Here is the above result in Maple syntax

-sqrt(-4*c^2 + 4*lambda^2*(k*x + 1)^4 - 4*c*x*(k*x + 2) - x^2*(k*x + 2)^2)*(2*sqrt(2*c*k - 1)*(-4*k^2*lambda^2 + 1)^(1/4)*(k*x + 1)*sqrt(k^2*(4*c^2 - 4*lambda^2*(k*x + 1)^4 + 4*c*x*(k*x + 2) + x^2*(k*x + 2)^2)/(-1 + 2*c*k + sqrt(-4*k^2*lambda^2 + 1) + k*sqrt(-4*k^2*lambda^2 + 1)*x*(k*x + 2))^2) + (-4*c*k + 2)*EllipticE(sin(2*arctan((-4*k^2*lambda^2 + 1)^(1/4)*(k*x + 1)/sqrt(2*c*k - 1))), sqrt(1/2 - 1/(2*sqrt(-4*k^2*lambda^2 + 1)))) + (2*c*k - 1)*(1 + sqrt(-4*k^2*lambda^2 + 1))*InverseJacobiAM(2*arctan((-4*k^2*lambda^2 + 1)^(1/4)*(k*x + 1)/sqrt(2*c*k - 1)), sqrt(1/2 - 1/(2*sqrt(-4*k^2*lambda^2 + 1)))))/(2*sqrt(2*c*k - 1)*(-4*k^2*lambda^2 + 1)^(3/4)*(-1 + 2*c*k + sqrt(-4*k^2*lambda^2 + 1) + k*sqrt(-4*k^2*lambda^2 + 1)*x*(k*x + 2))*sqrt(k^2*(4*c^2 - 4*lambda^2*(k*x + 1)^4 + 4*c*x*(k*x + 2) + x^2*(k*x + 2)^2)/(-1 + 2*c*k + sqrt(-4*k^2*lambda^2 + 1) + k*sqrt(-4*k^2*lambda^2 + 1)*x*(k*x + 2))^2))

Rubi gives simplest solution.

 

@Carl Love 

Your first one worked

     foo:= proc(..., {ic::`=`:= ()=()}) ....

I will use this. Thanks. Its default  type is equation, so now I can pass it, and it is still type equation.

But your second choice is not type equation. Maple says it is type expression sequence 

Thanks. Will use the first one you showed. It works for what I need.

restart;
foo:=proc(n::integer, {ic::{`=`, identical()}:= ()})
    print(whattype(ic));
    print(type(ic,`=`));
end proc;

foo(3);

@Carl Love 

But now I am able to call the top function with something which is not an equation and it passes through. WHich I do not want. I wanted Maple to catch this. May be I should give a new example of the problem. Instead of using [] as default value, I'll make a NULL.  

restart;
interface(warnlevel=4);
kernelopts('assertlevel'=2):

foo:=proc(n::integer,{ic::`=`:=NULL})      
   post_process(n+1,':-ic'=ic);
end proc;

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

Now foo can only be called, with ic of type equation. If not present, it will get NULL.   And the problem is now, when foo calls post_process, it will fail, since NULL is not an equation. 

foo(3)
Error, (in foo) invalid input: post_process expects value for keyword parameter ic to be of type `=`, but received NULL

if I do what you suggested, then error goes away, but also caller can now call foo() with [], which is not equation, and maple no longer detect it:

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

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

foo(3,':-ic'=[]); #no error from Maple. But I only want to pass `=` for ic.

The problem is that Maple wants default value for keyword. But keyword argument type I want is  equation.

I do not know what default value to give it, which is also of type equation. That is why I had [] there. And now have NULL.

May be we need a NULL EQUATION type !

@Carl Love 

Ok, thanks. I did not know this. This takes care of the first issue. I still have the second issue to figure out. I.e.

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)); #now works.

foo(3)  #error due to default value 

Currently as I said, I take care of this, by checking for nargs, which I'd like to avoid doing.

there is syntax error  

Error, `)` unexpected
 

 

@ecterrab 

Thank you for ConstantFirst. But it does not work exactly the way I wanted it for all examples. Here is one case

restart;

macro(_C = suffixed(_C, posint));

ConstantsFirst := u -> subsindets(subsindets(u, `*`, p -> `*`(op(map(op, [selectremove(type, subsindets([op(p)], _C, convert, `local`), _C)])))), _C, w -> c__||(substring(w, 3..-1))):

sol:=dsolve(diff(y(x),x) = x+y(x),y(x));

ConstantsFirst(sol);

What I want is otuput of  sort(sol)  but with _C1 replaced by c[1]. i.e. all terms with _Cn to appear at front with _Cn in front also of each term. Like this

restart;
sol:=dsolve(diff(y(x),x) = x+y(x),y(x));
sort(sol);

The above is what I want, but looking _C1 replaced by c__1 or c[1], like this

The original solution by vv posted in https://www.mapleprimes.com/questions/231221-How-To-Make-Sort-Work-With-Alias#comment275751  works on this and now thanks to your fix for latest Latex, the Latex no do not drop the constant

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:=dsolve(diff(y(x),x) = x+y(x),y(x));
sol:=subs(S, sort(sol));

Also the new version by vv below at https://www.mapleprimes.com/questions/231230-Why-Latex-Removes-Constant-From-Expression#comment275790  works on this

restart;

Cc:=proc(u)
  local c, Cc1 := C -> c[parse(convert(C,string)[3..])];
  subsindets(u, `*`,
    proc(u)
      local k,r;
      k,r:=selectremove(type, [op(u)], suffixed(_C,integer));
      if nops(k)<>1 then return u fi;
      `*`(Cc1(k[]),r[])
    end):
  subsindets(%, suffixed(_C,integer), Cc1)
end:

sol:= dsolve(diff(y(x),x) = x+y(x),y(x));
Cc(sort(sol));  #note, must call sort first

I am still testing all the other solutions posted so far to see if they work for all the cases I have. 

thanks to everyone for the help. This is not an easy problem. May be Maple eventially will have a build-in support for such feature.  It helps with the Latex final formating to make it look better.

 

@ecterrab 

By the way: what you tried to achieve is achievable directly using alias

Thank you. I know about alias. I was using it for a while. But alias does not work for what I want. That is why I  was using VV solution.

The issue is this: I want the constant of integration to be on front of terms. As it looks better. Instead of at the end.  Sometimes Maple shows it at end.

So need to use sort() but sort does not work when using alias. Here is an example

restart;
alias(seq(c[k]=_C||k,k=0..10)):
sol:=dsolve(diff(y(x),x) = x+y(x),y(x));

Now if I do sort() on the above, before calling Latex, sort does not work

sort(sol)

If I had not used alias, it would have worked

restart;
sol:=dsolve(diff(y(x),x) = x+y(x),y(x));
sort(sol);

That is why I no longer use alias. 

@tomleslie 

Thanks. I was using the solution code from the reference post I had at the top.

I will go now and try your method on my large file. So far, it looks good and Latex is not dropping the initial constant any more.

Still, I think Latex should not have dropped the constant, even if the user code being used might not be optimal. So there is an issue there.  

It will take a little bit time to test this so I am sure it works for all cases.

 

@vv 

I've tested it more, and it looks good so far.

btw, you forgot the actual sort command in your new method (so it now works for all cases and not this example)

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

sol:=dsolve(t^2*diff(diff(y(t),t),t)-t*diff(y(t),t)+5*y(t) = 0,y(t)):
subs(S, sort(sol));

Thanks.

@Carl Love 

I think there is something else. not just bad luck. but I had no problem uploading and displaying the content for a while  now. 

But now I can't upload and display content any more even using same worksheet which worked few days ago.

I assume there is someone at Maplesoft who maintains this site (This site belongs to Maplesoft I assume). If there an email to report mapleprimes problems, if so, that will be a good starting place. They should know the cause hopefully.

 

@ecterrab 

great information all in one place. thank you.

Is there a technical reason why  it translates sin(x)^2 to   \sin^{2}x   but inverse trig remain the same under mixed?  ie.  arcsin(x)^2  does not change to \arcsin^{2}x ? May be you mentioned this before.

It now looks unsymmetric:

restart;
Latex:-Settings(UseImaginaryUnit=i,
      UseColor = false,
      powersoftrigonometricfunctions=  mixed,
      leavespaceafterfunctionname = true,
      cacheresults = false,
      spaceaftersqrt = true  
);
expr:=sin(x)^2+arcsin(x)^2;
Latex(expr)

Compared to

Currently, there is no option for one to obtain the above. I tried all three (mix, computer, textbook).

May be you could consider adding an option or modifying the current mixed one, so as to keep the paranthesis there, even for the case of one argument. i.e. to show this instead

As this could sometimes can be more appealing than removing the () for the one argument case as it does now. (may be mixedkeepparanthesis value?)

ps. if this should be separate question, I can move it.

Thanks.

First 23 24 25 26 27 28 29 Last Page 25 of 71