Items tagged with programming

Feed

I'm trying to program a procedure that will return me a list of positions defining equally spaced points (planets) around a circumference, for example:
PSI := [0, Pi]; # Location of 2 planets
PSI := [0, ((2/3)*Pi) , ((4/3)*Pi) ]; # For 3 Planets
I'm new to maple so most commands are new to me, I tried building the size of the list with [0 $ n] because I want the first position to always be at 0 degrees. The first problem is that I get this error:

Error, reserved word `for` unexpected

 

nplanets := 2;

2

(1)

make_PSI :=
proc(nplanets);
local n,psin,i,PSI:
n = nplanets;
psin  :=(pi*2)/n;
PSI := [0 $ n];
for i from 1 to n do
 angle :=(psin*i);
 op(i,PSI) := angle;
end do;
end;

 

 

Error, reserved word `for` unexpected

 


Any advice would be appreciated!

Download planetspace.mw

I'm trying to calculate the trajectory of a 3-particle system. I defined my parameters. Wrote a do loop. Got the number of iterations I expected. But when I look at the tables of position for each particle after I run the loop, the trajectory only changes for the first iteration, then it stays the same. In other words, it shows that the particle moved slightly after the first increment of time, but thereafter it doesn't move.


 

for i to N do x[11] := x[1]+tau*vx[1]+(1/2)*tau^2*F[x1]; y[11] := y[1]+tau*vy[1]+(1/2)*tau^2*F[y1]; x[21] := x[2]+tau*vx[2]+(1/2)*tau^2*F[x2]; y[21] := y[2]+tau*vy[2]+(1/2)*tau^2*F[y2]; x[31] := x[3]+tau*vx[3]+(1/2)*tau^2*F[x3]; y[31] := y[3]+tau*vy[3]+(1/2)*tau^2*F[y3]; R[1] := [op(R[1]), [x[11], y[11]]]; R[2] := [op(R[2]), [x[21], y[21]]]; R[3] := [op(R[3]), [x[31], y[31]]]; V[1] := [op(V[1]), [vx[11], vy[11]]]; V[2] := [op(V[2]), [vx[21], vy[21]]]; V[3] := [op(V[3]), [vx[31], vy[31]]] end do:

101

(5)

 

I am coding a big module to solving my project : analyze function in math, but when I compile my module maple return "Error," but it doesn't tell me what error happened.

I check the maple help and it said:" If no msgString is given, error raises the most recently occurring exception" but I have no exception before. 

This is the pic of that error.

Thank for your help.

Please I am having problem with this code particularly the last subroutine

#subroutine 1

restart;
Digits:=30:

f:=proc(n)
    -25*y[n]+12*cos(x[n]):
end proc:

#subroutine 2

e1:=y[n+4] = -y[n]+2*y[n+2]+((1/15)*h^2+(2/945)*h^2*u^2+(1/56700)*h^2*u^4-(1/415800)*h^2*u^6-(167/833976000)*h^2*u^8-(2633/245188944000)*h^2*u^10-(2671/5557616064000)*h^2*u^12-(257857/13304932857216000)*h^2*u^14-(3073333/4215002729166028800)*h^2*u^16)*f(n)+((16/15)*h^2-(8/945)*h^2*u^2-(1/14175)*h^2*u^4+(1/103950)*h^2*u^6+(167/208494000)*h^2*u^8+(2633/61297236000)*h^2*u^10+(2671/1389404016000)*h^2*u^12+(257857/3326233214304000)*h^2*u^14+(3073333/1053750682291507200)*h^2*u^16)*f(n+1)+((26/15)*h^2+(4/315)*h^2*u^2+(1/9450)*h^2*u^4-(1/69300)*h^2*u^6-(167/138996000)*h^2*u^8-(2633/40864824000)*h^2*u^10-(2671/926269344000)*h^2*u^12-(257857/2217488809536000)*h^2*u^14-(3073333/702500454861004800)*h^2*u^16)*f(n+2)+((16/15)*h^2-(8/945)*h^2*u^2-(1/14175)*h^2*u^4+(1/103950)*h^2*u^6+(167/208494000)*h^2*u^8+(2633/61297236000)*h^2*u^10+(2671/1389404016000)*h^2*u^12+(257857/3326233214304000)*h^2*u^14+(3073333/1053750682291507200)*h^2*u^16)*f(n+3)+((1/15)*h^2+(2/945)*h^2*u^2+(1/56700)*h^2*u^4-(1/415800)*h^2*u^6-(167/833976000)*h^2*u^8-(2633/245188944000)*h^2*u^10-(2671/5557616064000)*h^2*u^12-(257857/13304932857216000)*h^2*u^14-(3073333/4215002729166028800)*h^2*u^16)*f(n+4):

e2:=y[n+3] = -y[n+1]+2*y[n+2]+(-(1/240)*h^2-(31/60480)*h^2*u^2-(67/1814400)*h^2*u^4-(109/53222400)*h^2*u^6-(18127/186810624000)*h^2*u^8-(64931/15692092416000)*h^2*u^10-(9701/59281238016000)*h^2*u^12-(20832397/3406062811447296000)*h^2*u^14-(11349439/51876956666658816000)*h^2*u^16)*f(n)+((1/10)*h^2+(31/15120)*h^2*u^2+(67/453600)*h^2*u^4+(109/13305600)*h^2*u^6+(18127/46702656000)*h^2*u^8+(64931/3923023104000)*h^2*u^10+(9701/14820309504000)*h^2*u^12+(20832397/851515702861824000)*h^2*u^14+(11349439/12969239166664704000)*h^2*u^16)*f(n+1)+((97/120)*h^2-(31/10080)*h^2*u^2-(67/302400)*h^2*u^4-(109/8870400)*h^2*u^6-(18127/31135104000)*h^2*u^8-(64931/2615348736000)*h^2*u^10-(9701/9880206336000)*h^2*u^12-(20832397/567677135241216000)*h^2*u^14-(11349439/8646159444443136000)*h^2*u^16)*f(n+2)+((1/10)*h^2+(31/15120)*h^2*u^2+(67/453600)*h^2*u^4+(109/13305600)*h^2*u^6+(18127/46702656000)*h^2*u^8+(64931/3923023104000)*h^2*u^10+(9701/14820309504000)*h^2*u^12+(20832397/851515702861824000)*h^2*u^14+(11349439/12969239166664704000)*h^2*u^16)*f(n+3)+(-(1/240)*h^2-(31/60480)*h^2*u^2-(67/1814400)*h^2*u^4-(109/53222400)*h^2*u^6-(18127/186810624000)*h^2*u^8-(64931/15692092416000)*h^2*u^10-(9701/59281238016000)*h^2*u^12-(20832397/3406062811447296000)*h^2*u^14-(11349439/51876956666658816000)*h^2*u^16)*f(n+4):

e3:=h*delta[n] = (-149/42-(16/245)*u^2-(1324/169785)*u^4-(559246/695269575)*u^6-(14310311/175207932900)*u^8-(170868550903/20641246574949000)*u^10)*y[n]+(128/21+(32/245)*u^2+(2648/169785)*u^4+(1118492/695269575)*u^6+(14310311/87603966450)*u^8+(170868550903/10320623287474500)*u^10)*y[n+1]+(-107/42-(16/245)*u^2-(1324/169785)*u^4-(559246/695269575)*u^6-(14310311/175207932900)*u^8-(170868550903/20641246574949000)*u^10)*y[n+2]+(-(67/1260)*h^2+(1241/198450)*h^2*u^2+(277961/366735600)*h^2*u^4+(26460409/333729396000)*h^2*u^6+(1363374533/168199615584000)*h^2*u^8+(16323847966961/19815596711951040000)*h^2*u^10)*f(n)+((188/105)*h^2+(5078/99225)*h^2*u^2+(556159/91683900)*h^2*u^4+(51834031/83432349000)*h^2*u^6+(67782373/1078202664000)*h^2*u^8+(1854079193287/291405833999280000)*h^2*u^10)*f(n+1)+((31/90)*h^2+(341/33075)*h^2*u^2+(79361/61122600)*h^2*u^4+(23456627/166864698000)*h^2*u^6+(1228061399/84099807792000)*h^2*u^8+(14797833720283/9907798355975520000)*h^2*u^10)*f(n+2)+(-(4/105)*h^2-(46/14175)*h^2*u^2-(809/1871100)*h^2*u^4-(27827/567567000)*h^2*u^6-(637171/122594472000)*h^2*u^8-(33500737/62523180720000)*h^2*u^10)*f(n+3)+((1/252)*h^2+(23/28350)*h^2*u^2+(809/7484400)*h^2*u^4+(27827/2270268000)*h^2*u^6+(637171/490377888000)*h^2*u^8+(33500737/250092722880000)*h^2*u^10)*f(n+4):

e4:=y[3] = -y[1]+2*y[2]+(-(1/240)*h^2-(31/60480)*h^2*u^2-(67/1814400)*h^2*u^4-(109/53222400)*h^2*u^6-(18127/186810624000)*h^2*u^8-(64931/15692092416000)*h^2*u^10-(9701/59281238016000)*h^2*u^12-(20832397/3406062811447296000)*h^2*u^14-(11349439/51876956666658816000)*h^2*u^16)*f(0)+((1/10)*h^2+(31/15120)*h^2*u^2+(67/453600)*h^2*u^4+(109/13305600)*h^2*u^6+(18127/46702656000)*h^2*u^8+(64931/3923023104000)*h^2*u^10+(9701/14820309504000)*h^2*u^12+(20832397/851515702861824000)*h^2*u^14+(11349439/12969239166664704000)*h^2*u^16)*f(1)+((97/120)*h^2-(31/10080)*h^2*u^2-(67/302400)*h^2*u^4-(109/8870400)*h^2*u^6-(18127/31135104000)*h^2*u^8-(64931/2615348736000)*h^2*u^10-(9701/9880206336000)*h^2*u^12-(20832397/567677135241216000)*h^2*u^14-(11349439/8646159444443136000)*h^2*u^16)*f(2)+((1/10)*h^2+(31/15120)*h^2*u^2+(67/453600)*h^2*u^4+(109/13305600)*h^2*u^6+(18127/46702656000)*h^2*u^8+(64931/3923023104000)*h^2*u^10+(9701/14820309504000)*h^2*u^12+(20832397/851515702861824000)*h^2*u^14+(11349439/12969239166664704000)*h^2*u^16)*f(3)+(-(1/240)*h^2-(31/60480)*h^2*u^2-(67/1814400)*h^2*u^4-(109/53222400)*h^2*u^6-(18127/186810624000)*h^2*u^8-(64931/15692092416000)*h^2*u^10-(9701/59281238016000)*h^2*u^12-(20832397/3406062811447296000)*h^2*u^14-(11349439/51876956666658816000)*h^2*u^16)*f(4):

e5:=h*delta[0] = (-149/42-(16/245)*u^2-(1324/169785)*u^4-(559246/695269575)*u^6-(14310311/175207932900)*u^8-(170868550903/20641246574949000)*u^10)*y[0]+(128/21+(32/245)*u^2+(2648/169785)*u^4+(1118492/695269575)*u^6+(14310311/87603966450)*u^8+(170868550903/10320623287474500)*u^10)*y[1]+(-107/42-(16/245)*u^2-(1324/169785)*u^4-(559246/695269575)*u^6-(14310311/175207932900)*u^8-(170868550903/20641246574949000)*u^10)*y[2]+(-(67/1260)*h^2+(1241/198450)*h^2*u^2+(277961/366735600)*h^2*u^4+(26460409/333729396000)*h^2*u^6+(1363374533/168199615584000)*h^2*u^8+(16323847966961/19815596711951040000)*h^2*u^10)*f(0)+((188/105)*h^2+(5078/99225)*h^2*u^2+(556159/91683900)*h^2*u^4+(51834031/83432349000)*h^2*u^6+(67782373/1078202664000)*h^2*u^8+(1854079193287/291405833999280000)*h^2*u^10)*f(1)+((31/90)*h^2+(341/33075)*h^2*u^2+(79361/61122600)*h^2*u^4+(23456627/166864698000)*h^2*u^6+(1228061399/84099807792000)*h^2*u^8+(14797833720283/9907798355975520000)*h^2*u^10)*f(2)+(-(4/105)*h^2-(46/14175)*h^2*u^2-(809/1871100)*h^2*u^4-(27827/567567000)*h^2*u^6-(637171/122594472000)*h^2*u^8-(33500737/62523180720000)*h^2*u^10)*f(3)+((1/252)*h^2+(23/28350)*h^2*u^2+(809/7484400)*h^2*u^4+(27827/2270268000)*h^2*u^6+(637171/490377888000)*h^2*u^8+(33500737/250092722880000)*h^2*u^10)*f(4):

 

#subroutine 3

 


inx:=0:
ind:=0:
iny:=1:
h:=Pi/4.0:
n:=0:
omega:=5:
u:=omega*h:
N:=solve(h*p = 500*Pi/2, p):

c:=1:
for j from 0 to 5 do
    t[j]:=inx+j*h:
end do:
#e||(1..6);
vars:=y[n+1],y[n+2],y[n+3],delta[n],y[n+4]:

printf("%6s%15s%15s%15s\n",
    "h","Num.y","Ex.y","Error y");
for k from 1 to N do

    par1:=x[0]=t[0],x[1]=t[1],x[2]=t[2],x[3]=t[3],x[4]=t[4],x[5]=t[5]:
    par2:=y[n]=iny,delta[n]=ind:
   

res:=eval(<vars>, fsolve(eval({e||(1..5)},[par1,par2]), {vars}));

    for i from 1 to 5 do
        exy:=eval(0.5*cos(5*c*h)+0.5*cos(c*h)):
        printf("%6.5f%17.9f%15.9f%13.5g\n",
        h*c,res[i],exy,abs(res[i]-exy)):
        
        c:=c+1:
    end do:
    iny:=res[5]:
    inx:=t[5]:
    for j from 0 to 5 do
        t[j]:=inx + j*h:
    end do:
end do:

 

 

 

 

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.

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;

    fi;

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]);

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?

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.

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

 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

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

 

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.

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.

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

 

 

 

 

 

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