Maple Questions and Posts

These are Posts and Questions associated with the product, Maple


I have a rather long Maple code and want it to be executed multiple times with a parameter changed each time.

Surely this can be done with the loop structure, but it seems the whole loop structure must be contained into one single execution group, which makes it to be a little inconvenient, since the code is too long.


So is there any alternative way to realize this utility?


Best regard and thanks!

I have a function defined which maps x to a polynomial.

The coefficients are highly precise floating point numbers, which is necessary since it needs to be accurate, however when I try to print the function it looks like a massive mess.

I tried to use print(evalf[4](f)); in an attempt to simplify it however this evaluation seems to have no effect on how it is displayed.

As I said, I can't use evalf when defining the function since it needs high precision.

Is there a way to do this without creating a clone of the function with the coefficients evaluated, just to print it on screen?


I'm trying to find a way to write in maple syntax a circle approximated with tangents; I'm not sure how to evaluate an equation that yields multiple functions as an output. I am able to do it in Derive6.1 and Desmos; however, I am not able to do it with maple.  Can someone people help me with the proper syntax? I'll leave a picture for what I want to be able to do in Maple.  I am trying to do with with vectors (parametrically).



Hi there!

Basically I want to compare graphs in one coordinate system, however one of the graphs is set to 0 everywhere if the values of the y-coordinates differ too much from the values of the other graph. The procedure is below, how can I get around that?

I have already checked that all the values are calculated correctly and are displayed properly if the values of the other graph

are close enough.

Unfortunately I dont know how to send pictures.

Thanks, Daniel


local SpeichervektorX, #speichert die Stützstellen
SpeichervektorYAbs1, SpeichervektorYAbs2, #speichert die Stützwerte des späteren Splines aus den                                                 #absoluten Fehlern von f2Nr1 bzw. f2Nr2
SpeichervektorYRel1, SpeichervektorYRel2, #speichert die Stützwerte des späteren Splines aus den                                                 #relativen Fehlern von f2Nr1 bzw. f2Nr2
i2, #Laufvariable
InterpolationsfunktionAbs1,InterpolationsfunktionAbs2, #speichert den Spline aus den absoluten Fehlern                                                        #von f2Nr1 bzw. f2Nr2
InterpolationsfunktionRel1,InterpolationsfunktionRel2, #speichert den Spline aus den relativen Fehlern                                                        #von f2Nr1 bzw. f2Nr2
GraphAbs1,GraphAbs2, #speichert den Graphen aus dem Spline aus den absoluten Fehlern                                        #von f2Nr1 bzw. f2Nr2
GraphRel1,GraphRel2, #speichert den Graphen aus dem Spline aus den relativen Fehlern                                        #von f2Nr1 bzw. f2Nr2
PunkteAbs1,PunkteAbs2, #speichert den Punktgraphen aus den absoluten Fehlern                                                  #von f2Nr1 bzw. f2Nr2
PunkteRel1,PunkteRel2; #speichert den Punktgraphen aus den relativen Fehlern                                                  #von f2Nr1 bzw. f2Nr2
SpeichervektorX := Vector[row](ObenN-UntenN+1);
SpeichervektorYAbs1 := Vector[row](ObenN-UntenN+1);
SpeichervektorYRel1 := Vector[row](ObenN-UntenN+1);
for i2 from UntenN to ObenN do
  SpeichervektorX[i2-UntenN+1] := i2; #Stützstellen definieren
  SpeichervektorYAbs1[i2-UntenN+1] := GaußKronrodQuadraturKurz(Unten2, Oben2, f2Nr1, G2Nr1, i2)-(int     (f2Nr1*diff(G2Nr1,x), x = Unten2 .. Oben2)); # Bestimmen des absoluten Fehlers von f2Nr1 für n=i2
  if (int(f2Nr1*diff(G2Nr1,x),x= Unten2..Oben2) <> 0) and (int(f2Nr2*diff(G2Nr2,x),x= Unten2..Oben2)     <> 0) then  #Bestimmen des relativen Fehlers von f2Nr1, falls dieser für beide Funktionen definiert                #ist
    SpeichervektorYRel1[i2-UntenN+1] := abs(SpeichervektorYAbs1[i2-UntenN+1]/(int(f2Nr1*diff(G2Nr1,x),     x = Unten2 ..    Oben2)))
  end if;
end do;
InterpolationsfunktionAbs1 := Spline(SpeichervektorX, SpeichervektorYAbs1, n); #Generierung des
   #  Splines aus Stützpunkten, die sich aus den absoluten Fehlern von f2Nr1 ergeben
GraphAbs1 := plot(InterpolationsfunktionAbs1, n = UntenN .. ObenN, color = green, legend = ["f1"]);
   #  Generierung des Graphen, der sich aus dem Spline aus den absoluten Fehlern von f2Nr1 ergibt
PunkteAbs1 := plot(SpeichervektorX, SpeichervektorYAbs1, style = point, color = orange);
   #  Generierung des Punktgraphen, der sich aus den absoluten Fehlern von f2Nr1 ergibt  
if (int(f2Nr1*diff(G2Nr1,x),x= Unten2..Oben2) <> 0) and (int(f2Nr2*diff(G2Nr2,x),x= Unten2..Oben2)     <> 0) then
   # falls der relative Fehler für beide Funktionen definiert ist analoges Vorgehen für die relativen     #Fehler
  InterpolationsfunktionRel1 := Spline(SpeichervektorX, SpeichervektorYRel1, n);
  GraphRel1 := plot(InterpolationsfunktionRel1, n = UntenN .. ObenN, color = green, legend = ["f1"]);
  PunkteRel1 := plot(SpeichervektorX, SpeichervektorYRel1, style = point, color = orange);
end if;


for i2 from UntenN to ObenN do
  SpeichervektorYAbs2[i2-UntenN+1]:= GaußKronrodQuadraturKurz(Unten2,Oben2,f2Nr2,G2Nr2,i2)-int           (f2Nr2*diff(G2Nr2,x),x= Unten2..Oben2); # Bestimmen des absoluten Fehlers von f2Nr2 für n=i2
  if (int(f2Nr1*diff(G2Nr1,x),x= Unten2..Oben2) <> 0) and (int(f2Nr2*diff(G2Nr2,x),x= Unten2..Oben2)     <> 0) then  #Bestimmen des relativen Fehlers von f2, falls dieser für beide Funktionen definiert ist
    SpeichervektorYRel2[i2-UntenN+1]:= abs(SpeichervektorYAbs2[i2-UntenN+1]/
    int(f2Nr2*diff(G2Nr2,x),x= Unten2..Oben2));
  end if;
end do;
InterpolationsfunktionAbs2:=Spline(SpeichervektorX,SpeichervektorYAbs2,n); #Generierung des
   #  Splines aus Stützpunkten, die sich aus den absoluten Fehlern von f2Nr2 ergeben
GraphAbs2:= plot(InterpolationsfunktionAbs2, n=UntenN..ObenN, color=red, legend = ["f2"]);
   #  Generierung des Graphen, der sich aus dem Spline aus den absoluten Fehlern von f2Nr2 ergibt
PunkteAbs2:= plot(SpeichervektorX,SpeichervektorYAbs2,style = point, color=blue);
   #  Generierung des Punktgraphen, der sich aus den absoluten Fehlern von f2Nr2 ergibt  
print(display({GraphAbs1,PunkteAbs1,GraphAbs2,PunkteAbs2}, title= "Absoluter Fehler",titlefont=["ROMAN",18])); # Ausgeben des Verleichsgraphen der absoluten Fehler
if (int(f2Nr1*diff(G2Nr1,x),x= Unten2..Oben2) <> 0) and (int(f2Nr2*diff(G2Nr2,x),x= Unten2..Oben2) <> 0) then # falls der relative Fehler definiert ist analoges Vorgehen für die relativen Fehler
  GraphRel2:= plot(InterpolationsfunktionRel2, n=UntenN..ObenN, color=red, legend = ["f2"]);
  PunkteRel2:= plot(SpeichervektorX,SpeichervektorYRel2,style = point, color=blue);
  print(display({GraphRel1,GraphRel2,PunkteRel1,PunkteRel2}, title= "Relativer Fehler", titlefont=       ["ROMAN",18])) # Ausgeben des Verleichsgraphen der relativen Fehler, falls diese definiert sind
end if;
end proc


I'm trying to create a list containg the indices of another list, ordered corresponding to the descending size of the first list.

Say I have the list L := [8 7 9 12];

I want to find the list i = [4 3 1 2]

I know this could be done one element at the time by doing some iterative loop:
i := [];
for j from 1 to size(L) do
    i := [op(i),index];
end do;

But I was wondering if anyone knew any fancy tricks to do this more concisely(and without destroying the original list)?

i want to solve an integration as a funstion of T, but it return the integral unevaluated, but when i change the place of "numeric option" it returns sth. what is the problem ?


simplify((2/pi)^(1/2)*(int((exp(-32.74123792568-0.8916456579806e-1*ln(4.852623952*10^9*v^2)))*exp(-v^2/(2*T))*v^3, v = 2 .. 100,numeric,AllSolutions)))

2^(1/2)*(1/pi)^(1/2)*(int(exp((-34.72985611*T-.1783291316*ln(v)*T-.5*v^2)/T)*v^3, v = 2 .. 100, AllSolutions))


simplify((2/pi)^(1/2)*(int((exp(-32.74123792568-0.8916456579806e-1*ln(4.852623952*10^9*v^2)), numeric)*exp(-v^2/(2*T))*v^3, v = 2 .. 100)), AllSolutions);







I'm attempting to find the eigenvectors of a matrix without using the eigenvector function.

The matrix in question is a covariance matrix:

XCov:=Matrix([[4048/5, -817/5, -122/5], [-817/5, 921/10, -1999/10], [-122/5, -1999/10, 8341/10]]);

I've already found the eigenvalues by solving for lambda:

 det := Determinant(XCov-lambda*IdentityMatrix(3));
  lambda := solve(det=0.0, lambda);

(Yes I'm reusing the eigenvalue variable for the set of eigenvalues once they've been found­čśĆ)

Anyway, I've now set up the first eigenvector I want to find as:
e1 := Vector([e11,e12,e13]);

Now, the equation to find this first eigenvector is XCov . e1 = lambda[1] . e1
I first tried putting whats on the left in a variable called eigscale(what the vector is translated to by the matrix):

eigscale := Multiply(XCov,e1);
Which returns a vector:
eigscale = [(4048/5)*e11-(817/5)*e12-(122/5)*e13,

Each component of this vector must equate to the corresponding component in the right vector:

lambda[1]*e1 = [7.943520930*e11, 7.943520930*e12, 7.943520930*e13]

At first I tried setting these vectors equal to each other and using a solve but of course it didnt like the equations being in a vector format. So I then seperated out each equation and gave the solve function a system of equations as it expects:

solve(eigscale[1] = lambda[1]*e1[1], eigscale[2] = lambda[1]*e1[2], eigscale[3] = lambda[1]*e1[3], [e11,e12,e13]);

But again, solve fails to solve them. The reason this time(I believe) is because it can't find an exact value for e11, e12 & e13.
When solving for an eigenvector we get
e11 = e11,
e12 = Ae11,
e13 = Be11 + Ce12

I was wondering if there was a way to do a partial solve to find the components in terms of each other?

Failing that, I'm aware I can do it manually through row operations but I believe that would require changing the format so that each equation is a component of a single vector:
eigsolve := Vector([eigscale[1] = lambda[1]*e1[1], eigscale[2] = lambda[1]*e1[2], eigscale[3] = lambda[1]*e1[3]]);

Since row operations cannot be performed on a equation of vectors (again, I believe).

Help appreciated!

Hello Everyone,


I have been working on a multi variable expression. I would like to have the intervals where the function is monotonically increasing. I am trying to study any available method for multivariable expressions.

I came across various papers and sites which are explicitly mentioned single variable equations. finding out the critical points and studying the sign of the first derivative. Same cannot be applied for the multi variable expression.

above link explain for single variable functions. I would be grateful if someone could explain me a method or idea  which helps me out in solving for multivariable functions


Thanks a lot in advance

Digits := 25;

# Setup.
de := diff( x(t), t ) = a * y(t), diff( y(t), t ) = b * x(t);
ic := x(0) = 1, y(0) = 0;
sol := dsolve( { de, ic } ):

# Sample values for specific parameter values.
a0, b0 := 1.0, 0.25:
T := evalf( [ seq( i, i=1..5 ) ] ):
X := [ seq( eval['recurse']( x(t), [ op( sol ), a = a0, b = b0 ] ), t=T ) ]:
Y := [ seq( eval['recurse']( y(t), [ op( sol ), a = a0, b = b0 ] ), t=T ) ]:

# Numerical solution.
sol := dsolve( { de, ic }, 'numeric', 'range'=min(T)..max(T), 'abserr'=1e-15, 'maxfun'=0, 'parameters'=[a,b] ):

# Procedure to return values for specific time and parameter values.
u := proc( t, a, b )
	sol( 'parameters' = [ ':-a' = a, ':-b' = b ] ):
		return eval( [ x( ':-t' ), y( ':-t' ) ], sol( t ) ):  
		return 10000:
    end try:
end proc:

# Procedure to return objective function.
r := proc( a, b )
	local A, t, p, q, x, y:
	A := ListTools:-Flatten( [ seq( u( t, a, b ), t=T ) ] -~ zip( (x,y) -> [x,y], X, Y ) ):
	return foldl( (p,q) -> p + q^2, 0, op(A) ):
end proc:

# Find parameter values for bet fit.
Optimization:-Minimize( 'r'(a,b), a=-10..10, b=-10..10 );

I was provided the code above by Maple support, to fit a model to data using the Optimization package. I have tried to adapt this to a situation where one might only have the X variable data and so the model should only fit to that data.  I did this by deleting the , y( ':-t' ) in the try catch statement and then having the zip statement read as zip( (x) -> [x], X).

When I try to run that code, I get the error:

Error, (in Optimization:-NLPSolve) invalid input: zip uses a 3rd argument, b, which is missing

Anybody have an idea how to solve this?



I am using maple in windows 10 and the code is not at all executing. already using 32 bit maple on same system.






I try to define the action of projectors of two discrete basis onto a general state. This works as expected when I define the projector by myself. However, when using the "Projector" command, I get a not fully simplified result; see below. It seems like there is a confusion with dot/tensor product.  Can somoeone help?




restart; with(Physics)

Setup(hilbertspaces = {{A, alpha}, {B, beta}}, quantumbasisdimension = {A = 1 .. N[a], B = 1 .. N[b]}, quantumdiscretebasis = {A, B, alpha, beta}, bracketrules = {%Bracket(Bra(A, i), Ket(Psi)) = Ket(beta, i), %Bracket(Bra(A, i), Ket(alpha, j)) = C[i, j], %Bracket(Bra(B, i), Ket(Psi)) = Ket(alpha, i), %Bracket(Bra(B, j), Ket(beta, i)) = C[i, j]})

[bracketrules = {%Bracket(%Bra(A, i), %Ket(Psi)) = Physics:-Ket(beta, i), %Bracket(%Bra(A, i), %Ket(alpha, j)) = C[i, j], %Bracket(%Bra(B, i), %Ket(Psi)) = Physics:-Ket(alpha, i), %Bracket(%Bra(B, j), %Ket(beta, i)) = C[i, j]}, disjointedspaces = {{A, alpha}, {B, beta}}, quantumbasisdimension = {A = 1 .. N[a], B = 1 .. N[b]}, quantumdiscretebasis = {A, B, alpha, beta}]



proj := Sum(Sum(Ket(A, i).Bra(A, i).Ket(B, j).Bra(B, j), i = 1 .. N[a]), j = 1 .. N[b])

Sum(Sum(Physics:-`*`(Physics:-Ket(A, i), Physics:-Ket(B, j), Physics:-Bra(A, i), Physics:-Bra(B, j)), i = 1 .. N[a]), j = 1 .. N[b])


proj2 := Projector(Ket(A, i)).Projector(Ket(B, i))

Physics:-`*`(Sum(Physics:-`*`(Physics:-Ket(A, i), Physics:-Bra(A, i)), i = 1 .. N[a]), Sum(Physics:-`*`(Physics:-Ket(B, i), Physics:-Bra(B, i)), i = 1 .. N[b]))



Sum(Sum(C[i, j]*Physics:-`*`(Physics:-Ket(A, i), Physics:-Ket(B, j)), i = 1 .. N[a]), j = 1 .. N[b])




Sum(Sum(Physics:-`*`(Physics:-Ket(A, i__1), Physics:-Bra(A, i__1), Physics:-Ket(alpha, i), Physics:-Ket(B, i)), i = 1 .. N[b]), i__1 = 1 .. N[a])



Sum(Sum(Physics:-`*`(Physics:-Ket(A, i), Physics:-Ket(B, j), Physics:-Bra(A, i), Physics:-Bra(B, j)), i = 1 .. N[a]), j = 1 .. N[b])-Physics:-`*`(Sum(Physics:-`*`(Physics:-Ket(A, i), Physics:-Bra(A, i)), i = 1 .. N[a]), Sum(Physics:-`*`(Physics:-Ket(B, i), Physics:-Bra(B, i)), i = 1 .. N[b]))






Two lines that look the same, produce different results. The first lines gives an error message, but the next line that looks the same, does not.

copying and pasting both lines in Notepad reveals the difference:

Determinant*(R1 . B+R2 . B+R3 . B+R4 . A)

Determinant(R1 . B+R2 . B+R3 . B+R4 . A)

It seems that there is a hidden character (the asterisk) in the first line that produces the error.

In the worksheet itself you cannot see the asterisk, but using the arrow keys you can notice that there is another character.

It's hard to debug your code if there are hidden characters.


restart; with(LinearAlgebra)


`Maple 2018.2, X86 64 WINDOWS, Nov 16 2018, Build ID 1362973`*`Standard Worksheet Interface, Maple 2018.2, Windows 10, November 16 2018 Build ID 1362973`


A := Matrix(4, 4, symbol = a, shape = symmetric)

B := Matrix(4, 4, symbol = b, shape = symmetric)

R1 := Matrix(4, 4); R1[1, 1] := 1; R2 := Matrix(4, 4); R2[2, 2] := 1; R3 := Matrix(4, 4); R3[3, 3] := 1; R4 := Matrix(4, 4); R4[4, 4] := 1


Error, (in LinearAlgebra:-Multiply) invalid arguments



-a[1, 4]*b[1, 2]*b[2, 3]*b[3, 4]+a[1, 4]*b[1, 2]*b[2, 4]*b[3, 3]+a[1, 4]*b[1, 3]*b[2, 2]*b[3, 4]-a[1, 4]*b[1, 3]*b[2, 3]*b[2, 4]-a[1, 4]*b[1, 4]*b[2, 2]*b[3, 3]+a[1, 4]*b[1, 4]*b[2, 3]^2+a[2, 4]*b[1, 1]*b[2, 3]*b[3, 4]-a[2, 4]*b[1, 1]*b[2, 4]*b[3, 3]-a[2, 4]*b[1, 2]*b[1, 3]*b[3, 4]+a[2, 4]*b[1, 2]*b[1, 4]*b[3, 3]+a[2, 4]*b[1, 3]^2*b[2, 4]-a[2, 4]*b[1, 3]*b[1, 4]*b[2, 3]-a[3, 4]*b[1, 1]*b[2, 2]*b[3, 4]+a[3, 4]*b[1, 1]*b[2, 3]*b[2, 4]+a[3, 4]*b[1, 2]^2*b[3, 4]-a[3, 4]*b[1, 2]*b[1, 3]*b[2, 4]-a[3, 4]*b[1, 2]*b[1, 4]*b[2, 3]+a[3, 4]*b[1, 3]*b[1, 4]*b[2, 2]+a[4, 4]*b[1, 1]*b[2, 2]*b[3, 3]-a[4, 4]*b[1, 1]*b[2, 3]^2-a[4, 4]*b[1, 2]^2*b[3, 3]+2*a[4, 4]*b[1, 2]*b[1, 3]*b[2, 3]-a[4, 4]*b[1, 3]^2*b[2, 2]





i want to generate grid for a C_D nozzle but i dont know ho to plot it. please help me how to plot.

alpha := 0;
beta := 2;
Imax := 11;
Jmax := 11;
L := 10;
`&Delta;&zeta;` := L/(Imax-1);

`&Delta;x` := `&Delta;&zeta;`;
`&Delta;&eta;` := 1/(Jmax-1);

printlevel := 2;
for i to Imax do for j to Jmax do x[i] := `&Delta;&zeta;`*(i-1); eta[j] := `&Delta;&eta;`*(j-1); z := (eta[j]-alpha)*ln((beta+1)/(beta-1))/(1-alpha); H[i] := 3+2*tanh(x[i]-6); H1[i] := 0; H2[i] := -H[i]; y[i, j] := -H[i]*(2*beta/(exp(z)+1)-beta-2*alpha)/(2*alpha+1); Y[i, j] := (H1[i]+(-H1[i]*x[i]+H2[i])/L)*eta[j] end do end do;



If I have an expression like this


maple has trouble to simplify the argument.

In particular is it possible to apply expand() only to the denominator?

This is meant in general, so if I have many terms with expressions like this (possibly of products with other functions in each term), I want this simplification to be done termwise for the arguments of the functions.

Expanding the fraction doesn't work as in frontend(expand, [f]).


I am looking to test ANOVA ( Two Way).Maple does not directly gives this possibility.I found a procedure from Mr Tannis but i can t run it? Some ideas?

3 4 5 6 7 8 9 Last Page 5 of 1500