Items tagged with loop loop Tagged Items Feed

I need to complete the definition of P km using a for loop so that km(n,m) returns n k=1 k m whenever n, m ∈ Z, n > 0, and m ≥ 0.( You must use a for loop in the variable k, with k ranging from 1 to n, to do this question in the manner requested.)

km is defined as 

description "km(n,m) returns the sum of k^m as k ranges from 1 to n.";
end proc; # km

Not sure where tostart..Any help appreciated...thank you

Dear all

I have query related to generating commutator table from given Lie algebra spanning symmetries of PDE, I have ten vectors that I need to commute with each other to constitute commutator table. I have calculated all the commutations manually using "symmetrycommutator" command.

My queries is, can I convert this operation into short loop type program which automatically calculate cummutation of vectors from 1 to 10.

The Maple file is attaches with this query for reference.

Dear all,

I am using Maple to perform numerical integrations. When the final index in the loop is set to 5, the computation is fast and the results are quickly delivered. When I set a number higher than that, even 6, the program gets really slow and often crashes.

I herewith attach the script I use to generate the results. I guess that there should be a problem of memory management and I tried to use gc() as suggested in some forms but without success. I would appreciate it if someone here could explain the reason behind the problem.

Thank you,

restart; Ts := 1.; sigma := 1.; C := 1.; B := 2./(1+C); with(inttrans); beta := B*Ts*omega; assume(Tb > 0); assume(u >= 0); FzzS := -(3/2)*u^3*((2*u+I*beta)*(exp(2*sigma*u)+sigma^2*exp(2*u))-4*sigma*u*((1+sigma)*u-1))/((2*u+I*beta)^2*exp((2*(1+sigma))*u)-4*u^2*((1+sigma)*u-1)^2); InvFzzS := simplify(invfourier(FzzS, omega, t)); logTimeMin := -2; logTimeMax := -1; NumSteps := 6; logTimeStep := evalf(1.0*(logTimeMax-logTimeMin)/NumSteps); curdirectory(); A := matrix(NumSteps, 2); T1 := Array(1 .. NumSteps); AF := Array(1 .. NumSteps); for i to NumSteps do logTime := evalf(i*logTimeStep+logTimeMin); curTime := evalf(10^logTime); A[i, 1] := curTime; A[i, 2] := evalf(Int(eval(InvFzzS, t = curTime), u = 0 .. infinity, epsilon = 10^(-5))); T1[i] := A[i, 1]; AF[i] := A[i, 2] end do






Working on a code to create random lines. Here is the code: 

M:=1; N:=1500; R3:=rand(1..3): # M=lines, N=steps

for i from 1 to M do
   for j from 0 to N do
   if j=1 then X[i,1]:=1; Y[i,1]:=0;
    elif j>1 then
        if r=1 then X[i,j]:=2*X[i,j-1]-X[i,j-2]; Y[i,j]:=2*Y[i,j-1]-Y[i,j-2]
        elif r=2 then X[i,j]:=X[i,j-1]+Y[i,j-1]-Y[i,j-2]; Y[i,j]:=Y[i,j-1]-X[i,j-1]+X[i,j-2];
        elif r=3 then X[i,j]:=X[i,j-1]-Y[i,j-1]+Y[i,j-2]; Y[i,j]:=Y[i,j-1]+X[i,j-1]-X[i,j-2];
      end if;
    end if;
  end do:
end do:

Now the code works fine. But I don't want the lines to cross its own path. I want it to stop if R[i,j]=R[i,k] for any 0<k<i-2 for j=0..N. What I have so far is:

for i from 1 to M do
  for j from 1 to 40 do
    for k from 1 to j-2 do
     if R[i,j]=K[i,k] then x:=j; print(b[i]=j); break; end if;
     end do;
   end do;
end do;

Now it works aswell, but it doesn't stop when it hits the crossing point. I want it to stop so i get one b[i]=j per M. So I need it to break two for loops so that it goes through i M times and stops everytime it reaches a crossing point

The title pretty much says it, but I wrote a bunch of code that operates on a matrix of given size. Now I want to increment that size with a loop, how can I put a loop around all the code? It won't let me just copy paste it into my loop body for some reason. Thanks!


i need help to translate a system which is given below to a for loop.

Other wise i am writing it with myself. 

instead of doing it like that 


sys := [galerkin_funcs[1], galerkin_funcs[2], galerkin_funcs[3], galerkin_funcs[4], galerkin_funcs[5], galerkin_funcs[6], galerkin_funcs[7], galerkin_funcs[8], galerkin_funcs[9], galerkin_funcs[10]];

var := [w[1], w[2], w[3], w[4], w[5], w[6]];

Kmat, Fmat := GenerateMatrix(sys, var);

i want to do it like that.


for i to N+4 do

sys(1,i) := galerkin_funcs[i] 

end do

for i to N do

var(1,i) := w[i] 

end do

After that i will generate matrix with this comman Kmat, Fmat := GenerateMatrix(sys, var);

But this for loop i wrote is not doing the i want to do.

Thanks for your help.



I am attempting to write a Gaussian elimination routine to solve a system Ax = b using loops, but I have been having trouble.  Any help would be mcuh appreciated.  Thanks!

I'm have used a program to find the roots of a function 


/ 1 \
x cos(x) - sin(x) sin|---- x|
\1000 /

x_max:=50; x_min:=-50; step:=2; i_max:=(x_max-x_min)/step;

for i from 0 to i_max by 1 do


and my output was of the form of multiple "potential" roots and a bunch of which are the same. So I tried to get rid of the ones which were the same before actually finding the ones which ARE roots. To do that I done....



j := 1; for j to 50 do if x[j]-x[j+1] = 0 then ignore(x[j]) else print(x[j]) end if end do:


and it got rid of the ones which are of the above form but some roots are the same and seperated by more than 1 ... i.e x[ j ]= x[j + 2] or some other number. 


Basically I am trying to generalise the above for loop for all "numbers" instead of 1 but when I try some things the for loop doesnt like it. 

Any help would be good!



Good Day Everybody, I m new to maple and would like to translate the following for loop from Matlab to Maple. The FromMatlab Translater didnt work for this expression related to the matrix Q, A, B D and A1. Any help would be greatly appreciated.

Related Matlab Code:



 for i=1:length(R)























Thanks a lot in advance.

I'm trying to write the results of a loop calculation to a file in maple format so that they can be read back in later.

This is a simple example.



for i from 1 to ni do
for j from 1 to nj do

# complicated calculations go here
result:=(x+y)^(i+j); # this is the result (example only)
# write calculated result to file as mat[i,j]:=calculated result; # this is the critical step



read(`outfile`);  # reads in calculated matrix

I don't want to set the result to mat in the loop to avoid memory issues while the terms in mat are calculated.

Does anyone know how to do this?


Dear all,

I'm having trouble defining a Maple procedure containing for loops. I have one outer for loop which I terminate at the end and two separate for loops of which the first one get's terminated before the second one starts. Nethertheless Maple complains, that my outer loop doesn't get terminated and points to to a point before the second inner for loop starts. I based this procedure on a procedure I defined in another worksheet and the latter one is working just fine, although the structure ist the same in both procedures. As far as I can see, the structure is

for n from 0 to T do
for i from 1 to J do
end do;
for i from J-2 to 1 by -1 do
end do;

end do;

I have several if statements in the procedure, too, but as far as I can see, everything is terminated fine. Perhaps there is something else wrong with my procedure and I'm just getting a strange error? I would really appreciateit, if somebody could take a short look at the problem. Since the procedure takes up several pages I'm uploading my Maple work sheet. The relevant procedure is the one defined just after the red comment "#  actual code" which is about 60% through the work sheet.

Thank you all.



I want to make a for loop inside another loop, but this code does not seem to work well.

for i from 0 to 10 do

  for n from 0 to 10 do


  end do

end do;




I want write loop for this code:

V := 24;

eq := {Eq2, Eq3};

ans := fsolve(eq, {a1 = 0, a3 = 0});

r := 0;

W1 := rhs(ans[1])*phi11(r)+rhs(ans[2])*phi21(r)

V and W1 is Variable, I change V and solve eq and determinen a1 and a3 after i calculated W1

I want write Loop for this,

can you help me????????/ 

I need to find all combinations of a binary list of length 3.  For example: [0,0,0] , [1,0,0] , [0,1,0] , [0,0,1] , [1,1,0] , [1,0,1] , [0,1,1], [1,1,1].  Does anyone have a procedure or can write a loop that does this?

Maple 2015, Windows 7 Pro

Notice the printout of the following example.  The true/false Maple evaluations are incorrect because I do not know what TYPE command to put in the printf expression.  However, the format of the printout is what I want.

r:= [17=15,16<17,17>18]:
printf("%{}9a\n\n%{}9a\n\n", <r>,<type~(r,anything)>)

  17 = 15   16 < 17   18 < 17

     true      true      true

In this second example the Maple evaluations of the statements are correct, but I want the print format to flow accross the page rather than down the page.

for r in [17 = 15, 16 < 17,18 < 17]
end do;
  17 = 15


  16 < 17


  18 < 17


Could someone show me how to modify the second example so that the printout will flow across the screen rather than down the screen.  Thanks in advance, Les  PS I'd like to keep the loop if possible.

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