Maple Questions and Posts

These are Posts and Questions associated with the product, Maple

Maple seems to have difficulty computing this sum, which occurs in molecular physics of the H atom.

fd := j -> 2^8*j^5*(j-1)^(2*j-4)/(3*(j+1)^(2*j+4));

sum(fd(n)*ln(1-1/n^2), n=2..infinity);

Can anybody discover a solution, please?

hi. 

i want to plot these two equation that z is complex. 

i try it by implicitplot but for the second one it's not work. thank you

I was trying to find if the type of module wide variable is considered local or global.

I have an exported variable in module. Maple then said it was local . OK

restart;
foo:=module()
   export n::integer;
   export boo:=proc()::integer;
     return n;
   end proc;       
end module;
                   

n:=foo:-boo():
type(n,`local`);

               # true

But when I did this

restart;
foo:=module()
   export n::integer;
end module;

n:=foo:-n;
type(n,`local`)

         #false

Now Maple says it no longer local.

What is the difference? The module wide variable is exported in both cases. So one can access it directly like in the second example above, or via call to a proc inside the module, which returns it.

Why in one case it is local and in the second case it is not?

Ok, I found the issue. It seems when doing return  n; in the first example above, it created and returned a local n to the proc itself (where n was not declared in the example). (even though maplemint did not complain. Strange).

I have assumed when doing return n Maple will know this is the module wide variable n since that is the closest one around.  i.e. the proc is inside the module. And sits inside the module. So return n should referenced this variable. But it did not, because when I changed the code to this

restart;
foo:=module()
   export n::integer;
   export boo:=proc()::integer;
     return foo:-n;
   end proc;       
end module;

n:=foo:-boo():
type(n,`local`);

     #false

Now it returned false. The same as the second example.

But it also returned false when asking if it is global

n:=foo:-boo():
type(n,`global`);

    #false

So the module wide variable in this example is not local and is not global.

Is there another type to use to check if the variable/symbol returned is a module wide type?

Maple 2020.2

I assume the goal is to have the Latex output close to the screen output in Maple. In these examples this is the case.

Example 1

restart;
A:=Matrix([[1,-1,0,2],[1,2,2,-2],[0,2,3,-1]]):
LinearAlgebra:-NullSpace(A)

But the Latex generated for the above, using the Latex() command is

\{ \left[\begin{array}{c}0 \\2 \\-1 \\1 \end{array}\right] \} 

Which when compiled

\documentclass[11pt]{article}
\usepackage{amsmath}
\begin{document}
\[
\{ \left[\begin{array}{c}0 \\2 \\-1 \\1 \end{array}\right] \} 
\]
\end{document}

gives

The latex should instead be 

\left\{ \left[\begin{array}{c}0 \\2 \\-1 \\1 \end{array}\right] \right\} 

Which compiles to

Example 2

restart;
A:=Matrix([[1,-1,0,2],[1,2,2,-2],[0,2,3,-1]]):
LinearAlgebra:-RowSpace(A)

The Latex of the above is 

[\left[\begin{array}{cccc}1 & 0 & 0 & 0 \end{array}\right], 
\left[\begin{array}{cccc}0 & 1 & 0 & -2 \end{array}\right], 
\left[\begin{array}{cccc}0 & 0 & 1 & 1 \end{array}\right]]

Which when compiled gives

\documentclass[11pt]{article}
\usepackage{amsmath}
\begin{document}
\[
[\left[\begin{array}{cccc}1 & 0 & 0 & 0 \end{array}\right], 
\left[\begin{array}{cccc}0 & 1 & 0 & -2 \end{array}\right], 
\left[\begin{array}{cccc}0 & 0 & 1 & 1 \end{array}\right]]
\]  
\end{document}

gives

A better Latex would be

\left[\left[\begin{array}{cccc}1 & 0 & 0 & 0 \end{array}\right], 
\left[\begin{array}{cccc}0 & 1 & 0 & -2 \end{array}\right], 
\left[\begin{array}{cccc}0 & 0 & 1 & 1 \end{array}\right]\right]

Which compiles to

Now the size of the [[ is the same on both ends.

example 3

restart;
A:=Matrix([[1,-1,0,2],[1,2,2,-2],[0,2,3,-1]]):
LinearAlgebra:-ColumnSpace(A)

The Latex given for the above is

[\left[\begin{array}{c}1 \\0 \\0 \end{array}\right], 
\left[\begin{array}{c}0 \\1 \\0 \end{array}\right], 
\left[\begin{array}{c}0 \\0 \\1 \end{array}\right]]

Which when compiled

\documentclass[11pt]{article}
\usepackage{amsmath}
\begin{document}
\[
[\left[\begin{array}{c}1 \\0 \\0 \end{array}\right], 
\left[\begin{array}{c}0 \\1 \\0 \end{array}\right], 
\left[\begin{array}{c}0 \\0 \\1 \end{array}\right]]
\]  
\end{document}

gives

A better Latex is

\left[\left[\begin{array}{c}1 \\0 \\0 \end{array}\right], 
\left[\begin{array}{c}0 \\1 \\0 \end{array}\right], 
\left[\begin{array}{c}0 \\0 \\1 \end{array}\right]\right]

Which compiles to 

Maple 2020.2 with Physics  891 

I'm trying to just use "ThermophysicalData:-Chemical" function  to calculate below:

1 mol water vapor(H2O,g) condenses to liquid water  at 100C and 101.325kPa

Is there a function embeded to calculate DeltaW/H/S while switching the phases of matter.

thank you.

 

Here is the problem. I am trying to use sort() to make solution to ode show up with constant of integrations _C1 at the front of the term, instead of how Maple shows it, which is after the term, which does not look good.

As recommened in  Why-Maple-Refuses-To-Change-Location

sort() works well. Except for this: I am also using alias for the constant of integrations, to get nicer Latex output, as recommended in earlier post (which I can't find now). 

But once I use alias, now sort no longer produce the result I want. Here is an example

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

Here sort works. It moved the term with constant of integration to the front, and _C1 at front, which is what I want as it looks more clear.

But when I do 

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

This is because, I am assuming, the order of _C1 is higher than c[1] and sort is using the alias of _C1 to sort on and not _C1 itself.

The only reason I am using alias, is to get nicer Latex output when converting the solution to Latex vs. when using _C1

Is there a way to tell sort to treat c[1] as _C1, and c[2] as _C2, etc...  in terms of lexicographical ordering?

I see an order option for the command sort() in help, but so far did not know how to use it for the above purpose. This only affects _C1,_C2,_C3,_C4,.. and nothing else and I only use sort() on the output of the solution of ode. May be I need to write an order function and in there tell it c[1] has same order as _C1? But _C1 has c[1] as alias? so I do not think this will not work.

Basically I want to use the alias, but also use sort() on the result as if these constants of integrations where _C1,_C2, etc..

in my code, I set the alias at the global level, before I call any function in my package.

Any ideas how to do this or workaround this?

Maple 2020.2 on windows

 

An exercise of 1948 commits me to form the equation of conics passing by 3 points. Let P=0, Q=0, R=0 be the equations of the sides of the triangle ABC; if we associate these sides 2 to 2 we obtain 3 conics passing through points A, B, C having for equations QR=0, RP=0, PQ=0. As a result, the general equation of conics around the triangle ABC is: aQR+bRP+cPQ=0. P, Q, R being equations of the form mx+ny+pz=0 (so-called homogeneous coordinates). Then change to refined coordinates with x+y+z=1 (formula found on the internet and surely misinterpreted). Is it necessary to change of base ? Thank you for your help.

Given a metric, to compute quantities in the NP formalism one needs to specify a null tetrad. In the various examples in the help pages, sometimes the tetrad is specified simply as a list of 4 vectors, e.g., NT := [...] and sometimes evalDG is applied as in NT := evalDG({...]). Using the first format, Maple accepted NT as argument in NPSpinCoefficients but  NPCurvatureScalars(SpinCoefficients,NT) complained that the second argument wasn't a list of four vectors. When I used the second format, both commands returned the expected results. Why the difference?

RobinsonTrautmanSpinDG.mw

I am facing difficulty to realize this double iterative process. 

The equations in question are 

The flow chart for the iterative process is given as


The different parameters are defined as

 

alphan:=1.72*10^(-4):
alphap:=2.037*10^(-4):
L:=1.3*10^(-3):
A:=2.08*10^(-6):
kp:=1.265:
kn:=1.011:
sigmap:=1.314e-5:
sigman:=1.119e-5:
alphapn:=alphap-alphan:
Rpn:=L/(A)*(sigmap+sigman):
RL:=1:
Kpn:=(A/L)*(kp+kn):
cf:=4205:
cc:=4153:
hf:=80:
hc:=1000:
Tfin:=773:
Tcin:=353:
mf:=20:
mc:=20:


Influence_of_different_cooling_methods_on_thermoelectric_performance_of_an_engine_exhaust_gas_waste_heat_recovery_system.pdf

Consider the second order BVP:

diff(u(x), x, x) = u(x), u(0) = 2, u(1) = 1

I want dsolve numeric to calculate the second derivative, diff(u(x), x, x)

The actual problem I am working on is a more complex BVP that cannot be solved symbolically, but this simpler BVP will illustrate the problem.

Several Mapleprimes posts say to add a second equation diff(u(x), x, x) = v(x) and solve the system for u(x), v(x). This works for IVP's. However, when I implement it as shown below for the BVP:

dsolve({diff(u(x), x, x) = u(x), diff(u(x), x, x) = v(x), u(0) = 2, u(1) = 1, v(1) = 1}, {u(x), v(x)})

dsolve solves the problem fine symbolically, but when I try to solve the problem numerically:

dsolve({diff(u(x), x, x) = u(x), diff(u(x), x, x) = v(x), u(0) = 2, u(1) = 1, v(1) = 1}, numeric)

I get the following error message:

Error, (in dsolve/numeric/bvp/convertsys) the ODE system does not contain derivatives of the unknown function v

The above dsolve numeric command is a simplifcation -- e.g. I use an approximate solution etc. -- dsolve numeric solves the original BVP just fine, but will NOT calculate the second derivative.

I have tried any number of variations. I can convert the original problem to a system of first order equations -- but then, of course, dsolve calculates no first derivatives -- so I don't have diff (u(x),x) = diff (u(x),x,x)! 

I've killed a whole day on this. I need to estimate the location of the inflection point in my real problem (the solution is a sigmoidal function). I can apply a finite difference approximation to the dsolve numeric solution, but it's not accurate enough. Dsolve should be more accurate, since dsolve will  regulate the error of the added variable, v(x), to within abserr.

Oh, you would make everyone's life so much easier if you would just have dsolve numeric return all the derivatives in the IVP/BVP being solved! Or provide a data struction as solution that can be integrated/differentiated.

Robert


 

 

 

I have a large Maple 2020 worksheet which contains images and text.  I have been asked to publish a paper on the worksheet, in which I need to include LaTeX format. I have attempted to make the Maple => LaTeX conversion, but have the resulting file is very cluttered and takes much time to clean.  Can anyone offer advice on the best way to get clean LaTeX document from a worksheet?

Melvin Brown

sympl55@gmail.com

 

Hi,

It seems that it's not possible to change the tickmarks on axis 2 of a sparsematrixplot.
Mire of this, trying to change them seems to suppress them...
Perhaps this was a problem in Maple 2015 which has since been corrected?
By any chance, would you have a trick to correct this?

TIA
 

restart:

interface(version)

`Standard Worksheet Interface, Maple 2015.2, Mac OS X, December 21 2015 Build ID 1097895`

(1)

M := LinearAlgebra:-RandomMatrix(20,density=0.25,generator=0 .. 1);

M := Vector(4, {(1) = ` 20 x 20 `*Matrix, (2) = `Data Type: `*anything, (3) = `Storage: `*rectangular, (4) = `Order: `*Fortran_order})

(2)

plots:-sparsematrixplot(
   M, matrixview
);

 

plots:-sparsematrixplot(
   M, matrixview
  ,axis[1]=[tickmarks=[seq(i=i-1, i in [seq](1..20, 5))]]
  ,axis[2]=[tickmarks=[seq(j=j-1, j in [seq](1..20, 5))]]
);

 

plots:-sparsematrixplot(
   M, matrixview
  ,axis[2]=[tickmarks=[seq(i=i-1, i in [seq](1..20, 5))]]
);

 

 


 

Download sparsematrixplot.mw

How I can plot3d function s. in the domain x ,y from -1300 to 200.

Thanks

if.mw
 

"restart;   #`    x__A`=-1300..200,      `y__A`=-1300..200    u1:=(((`x__A`-200)^(2)+(`y__A`^())^(2))*0.001)/(960000);   if  u1<=0.001  then w(u1):=-0.5772-ln(u1);  else if u1>0.001  then w(u1):=-0.5772-ln(u1)+u1-((u1)^(2))/(2*2!)+((u1)^(3))/(3*3!)-((u1)^(4))/(4*4!)+((u1)^(5))/(5*5!)-((u1)^(6))/(6*6!)+((u1)^(7))/(7*7!)-((u1)^(8))/(8*8!)+((u1)^(9))/(9*9!)-((u1)^(10))/(10*10!)+((u1)^(11))/(11*11!)-((u1)^(12))/(12*12!);     end if"

Error, invalid 'if' statement

"restart;      u1:=(((`x__A`-200)^2+(`y__A`)^2)*0.001)/960000;   if u1<=0.001  then w:=(u1)->-0.5772-ln(u1);  elseif u1>0.001  then w(u1):=-0.5772-ln(u1)+u1-((u1)^2)/(2*2!)+((u1)^3)/(3*3!)-((u1)^4)/(4*4!)+((u1)^5)/(5*5!)-((u1)^6)/(6*6!)+((u1)^7)/(7*7!)-((u1)^8)/(8*8!)+((u1)^9)/(9*9!)-((u1)^10)/(10*10!)+((u1)^11)/(11*11!)-((u1)^12)/(12*12!);     end if"

 

s := 6.87*10^(-3)*w(u1); plot3d(s, x__A = -1300 .. 200, y__A = -1300 .. 200)


 

Download if.mw

 

Hello,

Im exporting procedures defined in Maple to an external software and was planning to use the CodeGeneration -tools for that. How ever, i encountered quite surprising limitations.

 

First is default value for procedure parameter. The documentation explains that procedure parameter can be set to have a default value with syntax parameterName::type := defaultValue. And indeed, it works:

 

DefaultValueTest := proc(parameterWithDefaultValue::integer:=1)::integer;
	return parameterWithDefaultValue *2;
end proc;
DefaultValueTest();
                               2
DefaultValueTest(2);
                               4

However, apparently the CodeGenerator -package cannot handle it.

CSharp(DefaultValueTest);
Error, (in CodeGeneration:-IssueError) cannot translate initial value

This is not related to the chosen language, it wont work with Java or JavaScript translation either. Without the default value the generated code looks like this, as expected:

CSharp(DefaultValueTest);
public class CodeGenerationClass {
  public static System.Int32 DefaultValueTest (System.Int32 parameterWithDefaultValue)
  {
    return 2 * parameterWithDefaultValue;
  }
}

Whats up with this? Many if not all the CodeGeneration languages support default parameter value for function. In C# it would obviously be 

public static System.Int32 DefaultValueTest (System.Int32 parameterWithDefaultValue=1)

 

 

Another one is the type support. I was quite surprised that boolean type works fine in Maple but the codegeneration translation cannot handle it. For example:

Booltest := proc(boolVal::boolean)::integer;
	if ( boolVal = true ) then
		return 1;
	end if;
	
	return 0;
end proc;

Works fine in the maple.

Booltest(true);
                               1
Booltest(false);
                               0

But when ran trough the code generator:

CSharp(Booltest);
Warning, cannot translate type boolean, using default type
Error, (in CodeGeneration:-IssueError) cannot resolve types in {boolean, numeric}

Apparently, since the documentation says that if CodeGeneration doesn't recognize the type, it uses default type, which in this case is numeric, it cannot do the evaluation in the if clause ( numeric and boolean true ).

So if we change the if condition to a shorthand version:

if ( boolVal ) then

The csharp transpiled code looks like 

CSharp(Booltest);
Warning, cannot translate type boolean, using default type
public class CodeGenerationClass {
  public static System.Int32 Booltest (System.Double boolVal)
  {
    if (boolVal)
      return 1;
    return 0;
  }
}

 

Every languange in the codegeneration package has boolean type. So shouldn't there be a variable type bool in the translator/transpiler as well?

 

Is there a way around these problems? Are there plans on expanding the codegeneration/transpiler ruleset to cover these rather basic cases? 

 

 

 

 

 

This puzzling to me. First will show the code, then explain the problem

restart;
ode:=diff(diff(y(x),x),x)+8*diff(y(x),x)+25*y(x) = 1;
sol:=dsolve(ode);
sol:= y(x)= _C2*exp(-4*x)*sin(3*x)+ _C1*exp(-4*x)*cos(3*x) + 1/25;
sol:= y(x)= _C2*exp(-4*x)*sin(3*x)+ _C1*exp(-4*x)*cos(3*x) + 1/25;
sol:= y(x)= _C2*exp(-4*x)*sin(3*x)+ _C1*exp(-4*x)*cos(3*x) + 1/25;

restart;

sol:= y(x)= _C2*exp(-4*x)*sin(3*x)+ _C1*exp(-4*x)*cos(3*x) + 1/25;

I was trying to changing the constant of integrations, to make them show at front, where it is better. But Maple refused to do so. Here is the output:


 

interface(version)

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

restart;
ode:=diff(diff(y(x),x),x)+8*diff(y(x),x)+25*y(x) = 1;
sol:=dsolve(ode);
sol:= y(x)= _C2*exp(-4*x)*sin(3*x)+ _C1*exp(-4*x)*cos(3*x) + 1/25;
sol:= y(x)= _C2*exp(-4*x)*sin(3*x)+ _C1*exp(-4*x)*cos(3*x) + 1/25;
sol:= y(x)= _C2*exp(-4*x)*sin(3*x)+ _C1*exp(-4*x)*cos(3*x) + 1/25;

diff(diff(y(x), x), x)+8*(diff(y(x), x))+25*y(x) = 1

y(x) = exp(-4*x)*sin(3*x)*_C2+exp(-4*x)*cos(3*x)*_C1+1/25

y(x) = exp(-4*x)*sin(3*x)*_C2+exp(-4*x)*cos(3*x)*_C1+1/25

y(x) = exp(-4*x)*sin(3*x)*_C2+exp(-4*x)*cos(3*x)*_C1+1/25

y(x) = exp(-4*x)*sin(3*x)*_C2+exp(-4*x)*cos(3*x)*_C1+1/25

restart;

sol:= y(x)= _C2*exp(-4*x)*sin(3*x)+ _C1*exp(-4*x)*cos(3*x) + 1/25;

y(x) = _C2*exp(-4*x)*sin(3*x)+_C1*exp(-4*x)*cos(3*x)+1/25

 


Why restart is needed to make Maple keep the output same as input? is it possible to rewrite it without having to do restart?

Download why_restart_needed.mw

 

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