nm

11363 Reputation

20 Badges

13 years, 39 days

MaplePrimes Activity


These are questions asked by nm

What do folks think about adding \, space automatically after Maple's Latex output for sqrt command?

This is all using the new Latex command. Not the orginal latex() command.

For me, it looks much better. I did some tests, and see no negative effect by always adding \, at the end of \sqrt{}

The reason is this: If there is a symbol after sqrt(.....)<HERE> then the math looks like the symbol is almost inside the integral, when it should be out. By adding \, this makes it more clear and better looking.

It is possible to write macro in Latex to do this in preamble I suppose. But if it can be done in the source, then that will be much better as it will always be there without the need to write complicated macro to change it later in Latex. 

Here are 4 expressions to compare

One can see the current problem area and the effect of adding \, automatically. The space was added for each case above in the second column, even for those where it was needed (second and third expressions) to show that adding space has no negative side-effect even when not needed.

Here is the above raw latex used, compiled on Tex Live 2020 on Linux,  and the Maple worksheet below that.

\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{longtable}
\usepackage{mleftright}  
\mleftright

\begin{document}

\begin{longtable}{|p{3in}|p{3in}|}\hline
Default. No space after & With space added after\\\hline 
\[
\sqrt{\left(3+x \right)^{2}+1} a +\sin \left(x \right)
\]
&
\[
\sqrt{\left(3+x \right)^{2}+1}\, a +\sin \left(x \right)
\]\\\hline 
\[
\frac{\sqrt{\left(3+x \right)^{2}+1}}{5}+b
\]
&
\[
\frac{\sqrt{\left(3+x \right)^{2}+1}\,}{5}+b
\]\\\hline 
\[
\frac{\sqrt{x}}{5}+b
\]
&
\[
\frac{\sqrt{x}\,}{5}+b
\]
\\\hline 
\[
\frac{\sqrt{x^{2}+6} c}{5}+b
\]
&
\[
\frac{\sqrt{x^{2}+6}\, c}{5}+b
\]\\\hline 
\end{longtable}

\end{document}


 

interface(version);
Physics:-Version();

`Standard Worksheet Interface, Maple 2020.2, Windows 10, November 11 2020 Build ID 1502365`

`The "Physics Updates" version in the MapleCloud is 882. The version installed in this computer is 881 created 2020, November 21, 11:11 hours Pacific Time, found in the directory C:\Users\me\maple\toolbox\2020\Physics Updates\lib\`

restart;

Latex:-Settings(UseImaginaryUnit=i,
      UseColor = false,
      powersoftrigonometricfunctions= computernotation,
      leavespaceafterfunctionname = true,
      cacheresults = false
);

`* Partial match of  '`*UseImaginaryUnit*`' against keyword '`*useimaginaryunit*`' `

`* Partial match of  '`*UseColor*`' against keyword '`*usecolor*`' `

[powersoftrigonometricfunctions = computernotation, leavespaceafterfunctionname = true, cacheresults = false, useimaginaryunit = i, usecolor = false]

expr1:=sqrt((3+x)^2+1)*a+sin(x);
Latex(expr1)

((3+x)^2+1)^(1/2)*a+sin(x)

\sqrt{\left(3+x \right)^{2}+1} a +\sin \left(x \right)

expr2:=sqrt((3+x)^2+1)/5+b;
Latex(expr2)

(1/5)*((3+x)^2+1)^(1/2)+b

\frac{\sqrt{\left(3+x \right)^{2}+1}}{5}+b

expr3:=sqrt(x)/5+b;
Latex(expr3)

(1/5)*x^(1/2)+b

\frac{\sqrt{x}}{5}+b

expr4:=(sqrt((3+x^2)+3)*c)/5+b;
Latex(expr4)

(1/5)*(x^2+6)^(1/2)*c+b

\frac{\sqrt{x^{2}+6} c}{5}+b

 


(typo, should be sqrt, not int)

Download space_after_int.mw

I am having hard time understanding why Maple does this.

I have an integral, which maple could not integrate. So it returns int(....,x). Which is all fine. Then I used subsindets to force all terms in form e^(ln()+ln()+...) to expand in order to simplify the integrand, just for display purposes. 

subsindets returns back the integral unevaluated (as expected) but with integrand a little simpler, again as expected.

All is well so far.  

Then I find to my surprise, if I type the result back one more type, now the the integral actually evaluates.

Why? 

I have 2 questions on this.

1) If the original integral did not evaluate, why simplifying e^(ln()+ln()+...) makes it now evaluate? Did not Maple know this allready?

2) Why result back from subsindets remained unevaluated integral, and I had to type it again to see it now evaluates?

I found this after long time debugging, since this was done in code, not looking at screen. 

What happened is this: I store the result  of subsindets in a variable, and when I look at it in the debugger, I see int() still there, as expected.

I call a function to return back this result. I now see int() is gone!   So the act of just returning the result back, caused it to evaluate. Even though the orginal variable still had int() in it as. So returning the expression back, was equivalent to typing it again on the screen in the example below, which caused it to evaluate. 


Please see worksheet below.

interface(version);

`Standard Worksheet Interface, Maple 2020.2, Windows 10, November 11 2020 Build ID 1502365`

Physics:-Version();

`The "Physics Updates" version in the MapleCloud is 882. The version installed in this computer is 881 created 2020, November 21, 11:11 hours Pacific Time, found in the directory C:\Users\me\maple\toolbox\2020\Physics Updates\lib\`

restart;

expr:=int(-1/2*exp((ln(a+cos(1/2*x)^2)+(-2*a-2)*ln(cos(1/2*x)))/a)*(-1+cos(x))/sin(1/2*x)/cos(1/2*x)/(a+cos(1/2*x)^2),x);

int(-(1/2)*exp((ln(a+cos((1/2)*x)^2)+(-2*a-2)*ln(cos((1/2)*x)))/a)*(-1+cos(x))/(sin((1/2)*x)*cos((1/2)*x)*(a+cos((1/2)*x)^2)), x)

#try again
expr;

int(-(1/2)*exp((ln(a+cos((1/2)*x)^2)+(-2*a-2)*ln(cos((1/2)*x)))/a)*(-1+cos(x))/(sin((1/2)*x)*cos((1/2)*x)*(a+cos((1/2)*x)^2)), x)

expr:=subsindets(expr,'specfunc( anything, exp )',f->(`if`(has(op(1,f),'ln'),expand(f),f)));

int(-(1/2)*(a+cos((1/2)*x)^2)^(1/a)*(-1+cos(x))/(cos((1/2)*x)^3*(cos((1/2)*x)^(1/a))^2*sin((1/2)*x)*(a+cos((1/2)*x)^2)), x)

#notice, the above is still int. Why is typing expr again, now makes it evaluate??
expr

-((4*a*exp(I*x)+exp((2*I)*x)+2*exp(I*x)+1)^(1/a)*exp(-((1/2)*I)*(2*csgn(I*exp(I*x)+I)*Pi*csgn(I*cos((1/2)*x))^2-2*csgn(I*exp(I*x)+I)*Pi*csgn(I*cos((1/2)*x))*csgn(I*exp(-((1/2)*I)*x))-2*Pi*csgn(I*cos((1/2)*x))^3+2*Pi*csgn(I*cos((1/2)*x))^2*csgn(I*exp(-((1/2)*I)*x))-Pi*csgn(I*exp(I*x))^3+2*Pi*csgn(I*exp(I*x))^2*csgn(I*exp(((1/2)*I)*x))-Pi*csgn(I*exp(I*x))*csgn(I*exp(((1/2)*I)*x))^2-Pi*csgn(I*a*exp(I*x)+((1/4)*I)*exp((2*I)*x)+((1/2)*I)*exp(I*x)+(1/4)*I)*csgn(I*a+(1/2)*I+((1/2)*I)*cos(x))^2+Pi*csgn(I*a*exp(I*x)+((1/4)*I)*exp((2*I)*x)+((1/2)*I)*exp(I*x)+(1/4)*I)*csgn(I*a+(1/2)*I+((1/2)*I)*cos(x))*csgn(I*exp(-I*x))+Pi*csgn(I*a+(1/2)*I+((1/2)*I)*cos(x))^3-Pi*csgn(I*a+(1/2)*I+((1/2)*I)*cos(x))^2*csgn(I*exp(-I*x))-4*x*a)/a)/((exp(I*x)+1)^(1/a))^2-2*(4*a*exp(I*x)+exp((2*I)*x)+2*exp(I*x)+1)^(1/a)*exp(-((1/2)*I)*(2*csgn(I*exp(I*x)+I)*Pi*csgn(I*cos((1/2)*x))^2-2*csgn(I*exp(I*x)+I)*Pi*csgn(I*cos((1/2)*x))*csgn(I*exp(-((1/2)*I)*x))-2*Pi*csgn(I*cos((1/2)*x))^3+2*Pi*csgn(I*cos((1/2)*x))^2*csgn(I*exp(-((1/2)*I)*x))-Pi*csgn(I*exp(I*x))^3+2*Pi*csgn(I*exp(I*x))^2*csgn(I*exp(((1/2)*I)*x))-Pi*csgn(I*exp(I*x))*csgn(I*exp(((1/2)*I)*x))^2-Pi*csgn(I*a*exp(I*x)+((1/4)*I)*exp((2*I)*x)+((1/2)*I)*exp(I*x)+(1/4)*I)*csgn(I*a+(1/2)*I+((1/2)*I)*cos(x))^2+Pi*csgn(I*a*exp(I*x)+((1/4)*I)*exp((2*I)*x)+((1/2)*I)*exp(I*x)+(1/4)*I)*csgn(I*a+(1/2)*I+((1/2)*I)*cos(x))*csgn(I*exp(-I*x))+Pi*csgn(I*a+(1/2)*I+((1/2)*I)*cos(x))^3-Pi*csgn(I*a+(1/2)*I+((1/2)*I)*cos(x))^2*csgn(I*exp(-I*x))-2*x*a)/a)/((exp(I*x)+1)^(1/a))^2+(4*a*exp(I*x)+exp((2*I)*x)+2*exp(I*x)+1)^(1/a)*exp(-((1/2)*I)*Pi*(2*csgn(I*exp(I*x)+I)*csgn(I*cos((1/2)*x))^2-2*csgn(I*exp(I*x)+I)*csgn(I*cos((1/2)*x))*csgn(I*exp(-((1/2)*I)*x))-2*csgn(I*cos((1/2)*x))^3+2*csgn(I*cos((1/2)*x))^2*csgn(I*exp(-((1/2)*I)*x))-csgn(I*exp(I*x))^3+2*csgn(I*exp(I*x))^2*csgn(I*exp(((1/2)*I)*x))-csgn(I*exp(I*x))*csgn(I*exp(((1/2)*I)*x))^2+csgn(I*a*exp(I*x)+((1/4)*I)*exp((2*I)*x)+((1/2)*I)*exp(I*x)+(1/4)*I)*csgn(I*a+(1/2)*I+((1/2)*I)*cos(x))*csgn(I*exp(-I*x))-csgn(I*a+(1/2)*I+((1/2)*I)*cos(x))^2*csgn(I*exp(-I*x))-csgn(I*a*exp(I*x)+((1/4)*I)*exp((2*I)*x)+((1/2)*I)*exp(I*x)+(1/4)*I)*csgn(I*a+(1/2)*I+((1/2)*I)*cos(x))^2+csgn(I*a+(1/2)*I+((1/2)*I)*cos(x))^3)/a)/((exp(I*x)+1)^(1/a))^2)/((a+1)*(exp(I*x)+1)^2)

 


 

Download why_it_now_evaluates.mw

Another simpler example, is just doing assignment to new variable. This causes evaluation.

restart;
expr:=int(-1/2*exp((ln(a+cos(1/2*x)^2)+(-2*a-2)*ln(cos(1/2*x)))/a)*(-1+cos(x))/sin(1/2*x)/cos(1/2*x)/(a+cos(1/2*x)^2),x);
expr:=subsindets(expr,'specfunc( anything, exp )',f->(`if`(has(op(1,f),'ln'),expand(f),f)));
#the above still has int() in it.

#this assignment, also causes evaluation
A:=expr;

 

What is the logic behind this. 

restart;
expr:=int(f(x),x);
lprint(algsubs(int=Int,expr));
lprint(subs(int=Int,expr));

gives


   int(f(x),x)

   Int(f(x),x)

So algsubs failed to replace int by Int

Looked at help. and see nothing. But I might have overlooked something. It says

It is a generalization of the subs command, which only handles syntactic substitution.

Generalization? If so, I expected it to work here. But may be there is a subtle reason why it did not? May be with algsubs, the replacement has to be algebraic expression and "int" is not, it is just a name.

Maple 2020.2
 

Hello Maple experts.

According to our teacher class notes, the ODE   y'=2*sqrt(y) with IC  y(0)=0 has 2 solutions. y(0)=0 and sqrt(y)=x

I am not able to get Maple to give the second solution,. It only gives y(0)=0.

Is there an option I am overlooking to make it give the other solution sqrt(y)=x ?

ode := diff(y(x),x) = 2*sqrt(y(x));
ic:=y(0)=0;
sol:=dsolve([ode,ic],y(x));

One can see the other solution by doing this

ode := diff(y(x),x) = 2*sqrt(y(x));
ic:=y(0)=A;
sol:=dsolve([ode,ic],y(x));
subs(A=0,sol)

I tried this in Mathematica. Mathematica does not give y=0 but it gives the second solution

I tried the singsol=all also, but it had no effect. Maple only shows the y(0)=0 solution.

Any suggestions?

Maple 2020.2

 

inside a local proc, when calling a  function such as map using the syntax map(x->x^2, target) does one need to declare as local inside the proc?

Same for other Maple calls, which uses something similar. For example 

subsindets(expr,'specfunc( anything, csgn )', f->simplify(f));

does one need to declare local to the proc where the above call is made?

Which one of these two example is more correct?

restart;
foo:=proc(expr)
  local x;
  map(x->x^2,expr);
end proc;

foo([x,y])

vs.

restart;
foo:=proc(expr)
    map(x->x^2,expr);
end proc;
foo([x,y])

In Mathematica for example, such symbols used by similar functions of the system (for example, Plot command, and others) are automatically localized to the system call itself avoiding any conflict with user own symbols.

I am not sure how Maple handles this. Should one always declare these symbols?

Maple 2020.2

 

 

First 104 105 106 107 108 109 110 Last Page 106 of 200