## View/modify the coding of worksheets and applicati...

Hi,

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.

## out of bound cases...

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:

## Why my function not work?...

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;`

`    fi;`

`end proc:`

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

## how to write better for passing parameter which is...

for example

func1 := proc(system1)

for i from 1 to 100 do

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

od:

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?

## Improved Josephus Algorithm in Maple. Need help....

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:
else
count := floor(n / k):
result := JosephusImproved(n - count, k):
result := result - n mod k:
if result < 0 then
result := result + n
else
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.

Cheers.

## How can I make a procedure control the font of the...

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?

## Is it possible to have a procedure write to execut...

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.

## Float Infinity instead of integer...

Hi I have this code

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

psi2=proc(a,x);
psi(a,x):=(1/sqrt(sqrt(pi)*2^a*factorial(a))*exp(-x^2/2)*HermiteH(a,x))
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;
result=proc(n,a);
result(n,a)=psi*psi2
end proc;
print(evalf(int(result(n,a),x=0..infinity)));
od;
od;```

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

## Why code not work?...

My code

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

Let

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};

Thanks you very much.

## "If" not passing through...

Hello!

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:
http://imgur.com/a/DGlgl

```
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.

## Bug in Optimization

Maple 2016

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 http://www.mapleprimes.com/questions/204750-Bug-In-LPSolve-In-Maple-20151).

## How many ways can sin(x) be called in Maple?...

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

Can you find more ways?

evalf(sin(Pi/2));
evalf(`sin`(Pi/2));
evalf('sin'(Pi/2));
`evalf/sin`(Pi/2);

## why Maple code sometimes surrounds key words or bu...

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 vers...

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

## How to use recursion in Maple...

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;
print(c);
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 `a`and `b` are both lists and arguments of the procedure and `c`being 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
﻿