Items tagged with programming


I am new in Maple and I would like to create some worksheets and applications based on ones found already on the Maple sites. Is there any way to see how they have been created? To see and modify the coding where necessary? Your help would be highly appreciated. Thank you for your support.

i got some trouble when i tried to build large matrix. in my case, notification error out of bound appear when looping stop at 9 from 24 repeatation. 

and this is my looping command:

the result of the script was:

now i feel so desperate so finish my final project because the error, please help me

I want write function get value a1, a2, ..., an to b1, b2, ..., bn.

Example get 1, 3, -9, 5 to a, b, c, d. This is my code

myfunc := proc(oldVars,newVars)

    local i;

    if nops(oldVars) = nops(newVars) then

        for i from 1 to nops(newVars) do

            newVars[i] := oldVars[i];



end proc:

But not work! Can someone help me. Thank you very much

for example

func1 := proc(system1)

for i from 1 to 100 do

solve([system1[1], system1[2]],[x,y]);


end proc:


func1([diff(y,t) = data[i+t+1], diff(x,t) = data[i+t+1]])

i is depend on the for loop inside a function, but woud like to pass this system into a function with i

this will cause error

how to write better for passing a system as parameter using variable inside a function?

Hello, everyone. I have a group project where we have to explain the Josephus problem and use Maple to solve the problem. I am trying to solve the problem in multiple ways (because why not), but I am struggling with my third procedure. I understand the logic behind it and how its supposed to achieve O(k*logn), but the code that I wrote for it doesn't seem to produce the correct result.

JosephusImproved := proc (n, k)
local count, result:
if n = 1 then
return 0:
elif 1 < n < k then
return JosephusImproved(n - 1, k) + k + 1 mod n:
count := floor(n / k):
result := JosephusImproved(n - count, k):
result := result - n mod k:
if result < 0 then
result := result + n
result := floor(result /(k - 1)):
return result:
end if:
end if:
end proc:

Note: The regular recursive expression [Josephus(n - 1, k) + k + 1 mod n] has a "+ 1" since that was the only way I could make Maple do the calculation correctly. Proven with a Cyclic procedure I already made.
Note 2: I am using Maple 2016 and 2D Math.

I would like some insight as to how I could fix this so that it works, just like the regular recursive procedure and cyclic list that I have.


I want to make the blue output my procedure spits out a another color, and align it to the right, is this even possible? Or something like it?

I basically want to make a Maple procedure that does certain calculations and writes the explanation for each calculation. I do however want Maple to write these explanations as a text field like in a normal Maple worksheet, instead of the blue output in the middle. Is this possible? Or is there any alternative ideas you have that I could try? Would really appreciate any kind of help, thanks.

Hi I have this code

 end proc;
 psi := proc(n, x) exp(-1/2*x^2)*HermiteH(n, x)/sqrt(sqrt(pi)*2^n*n!) end proc

 end proc;
psi2 = (proc(a, x)
    psi(a, x) := exp(-1/2*x^2)*HermiteH(a, x)/sqrt(sqrt(pi)*2^a*a!)

end proc)
 for n from 0 to 2 do;
 for a from 0 to 2 do;
 end proc;

it returns

 Float(infinity) signum(result(0, 0))

                     Float(infinity) signum(result(0, 1))

                     Float(infinity) signum(result(0, 2))

                     Float(infinity) signum(result(1, 0))

                     Float(infinity) signum(result(1, 1))

                     Float(infinity) signum(result(1, 2))

                     Float(infinity) signum(result(2, 0))

                     Float(infinity) signum(result(2, 1))

                     Float(infinity) signum(result(2, 2))

I know the results for (0,0), (1,1) and (2,2) should be 1 and the rest should be 0.

Can anybody help fix this please

My code

checkInSet := proc(L, x)
    local i;
    if nops(L) = 0 then
        return 0;
        for i from 1 to nops(L) do
            if x = L[i] then
                return i;
end proc:



M := {(a-2*b-2*c)^2*(2*a-b+2*c)^2, (a-2*b-c)^2*(a-b+2*c)^2, (a-2*b+c)^2*(a+b-2*c)^2, (a-2*b+2*c)^2*(2*a+b-2*c)^2, (a-b-2*c)^2*(2*a-b+c)^2, (a-b-c)^2*(a-b+c)^2, (a-b+c)^2*(a+b-c)^2, (a-b+2*c)^2*(2*a+b-c)^2, (a+b-2*c)^2*(2*a-b-c)^2};


But checkInSet(M, (a-2*b-2*c)^2*(2*a-b+2*c)^2) not work? Someone please help me.

Thanks you very much.


I was creating this code for the "Müller Method" for Numerical Analysis. Everything works fine till the if (for getting the x3) goes on. The problem is, the Maple doesn't detects the if.
I tried checking every variable and every variable is calculated except "x3"; even "disc".

I would like to know what happened. Anyways, here's the code:

x0 := 0; x1 := 8.4; x2 := 10; iter := 1000; tol := 10^(-8); f := proc (x) options operator, arrow; 3*x^3+7*x^2+x+2 end proc; f(x); plot(f(x), color = green); printf(" n          x0               x1               x2              x3                Error \n"); for i to iter do d0 := evalf((f(x1)-f(x0))/(x1-x0)); d1 := evalf((f(x2)-f(x1))/(x2-x1)); h1 := evalf(x2-x1); h0 := evalf(x1-x0); a := evalf((d1-d0)/(h1-h0)); b := evalf(a*h1+d1); c := evalf(f(x2)); disc := sqrt(-4*a*c+b^2); if abs(b+disc) > abs(b-disc) then x3 := x2+(-2*c)*(1/(b+sqrt(-4*a*c+b^2))); erry := abs((x3-x2)/x3) else x3 := x2+(-2*c)*(1/(b-sqrt(-4*a*c+b^2))); erry := abs((x3-x2)/x3) end if; if erry > tol then x0 := x1; x1 := x2; x2 := x3; printf("%2d     %2.8f      %2.8f       %2.8f         %2.5 f     %2.8 f \n", i, a, b, c, x3, erry) else printf("una raiz es: %2.8f ", x3); break end if end do;

I put the image (as it looks on my maple) and the "code" so you can copy-paste it in Maple.

Let us consider the linear integer programming problem:

A := Matrix([[1, 7, 1, 3], [1, 6, 4, 6], [17, 1, 5, 1], [1, 6, 10, 4]]):
 n := 4; z := add(add(A[i, j]*x[i, j], j = 1 .. n), i = 1 .. n):
restr := {seq(add(x[i, j], i = 1 .. n) = 1, j = 1 .. n), seq(add(x[i, j], j = 1 .. n) = 1, i = 1 .. n)}:
 sol := Optimization[LPSolve](z, restr, assume = binary);

Error, (in Optimization:-LPSolve) no feasible integer point found; 
use feasibilitytolerance option to adjust tolerance

sol1 := Optimization[LPSolve](z, restr, assume = binary, feasibilitytolerance = 100, integertolerance = 1);

Error, (in Optimization:-LPSolve) no feasible integer point found;
 use feasibilitytolerance option to adjust tolerance

That was OK in Maple 16, outputting


The bug in one of the principal Maple commands lasts since Maple 2015, where the above code causes "Kernel connection has been lost". The SCRs about it were submitted three times (see

I found 4 ways so far to call a Maple sin function (to return numerical value).

Can you find more ways?







I am maple newbie. Sometimes when I look at Maple code to try to understand the algorithm (which is hard, since I do not know Maple well), I see the code puts ` ` around some keywords. And sometimes it does not. For example, sometimes I see something like (these are random samples) from Maple code shown using showstat()

return `if`(assigned(r),r,{})
r := `union`(r,{solve(op(1,expr) = 1,vs)})
v2 := `intersect`(vs,indets(op(1,expr),'name'));

But sometimes, they do not put ` ` around functions name or keywords, like this:

if nops(v2) = 1 then
t1 := remove(a -> has(a,RootOf),t1);
for t in expr do

and so on.

Can some expert please give what is the rule thumb to use? Should user adopt this method also? When to put ` ` and when not to put ` `?   I understand that ` ` prevents one-time evaluation (or rather, holds off immediate evaluation) and ``  `` prevents two times evaluation and so on. But when to use ` ` is what is confusing me.


how to convert a nested for loop to iterative version with stack

I was trying to write a procedure that would compute a simple linear equation using the Extended Euclidean Algorithm. I was thinking of a procedure like the following:

solveEeaMatrix := proc (a::list, b::list) 
 local c::list;  
 c := a -iquo(a[1],b[1])*b;  
 while (c[1] <> gcd(a[1],b[1]) do 

I am basically stuck at this part as

1) I don't know how to setup a multi-dimensional array that could dynamically grow(as a possible solution).

2) I can't come up with a recursive function that could possibly take care of this.

In short, if I am given for example an equation like: 84*x+203*y = 14

I will transform it into 2 linear equation as follow:
row0 := [203, 0, 1] row1 := [84, 1, 0] Subsequently, I will perform the following:

c := a -iquo(a[1],b[1])*b;  

Where aand b are both lists and arguments of the procedure and cbeing another list and a local variable.

But I don't know how to do the following programmatically:

row3 := row1-iquo(row1[1], row2[1])*row2;
row4 := row2-iquo(row2[1], row3[1])*row3;
row5 := row3-iquo(row3[1], row4[1])*row4;
and so on ...                  

Any hint would be appreciated.

1 2 3 4 5 6 7 Last Page 1 of 11