Items tagged with loop loop Tagged Items Feed

I have about a year of experience in Maple, but as we know, we often come accross very simple problems that are difficult to find solutions to. Part of the problem is that I have not used conditional tests within for loops before.

I have a very large matrix, but until I solidify the algorithm, I'm practicing on a small matrix.

I created a 3 by 3 fibonacci matrix A:=<21,5,1|13,3,1|6,2,0>

I am trying to change the 1s to 0s without specific index reference. Here is my psuedocode that I hope to work on after some tips:

  • for i from 1 to 9
    if A[k] = 1 then
    end if
    end do


I get an error message saying "unterminated for loop," which is confusing me.

Hallo. I'd like to use two commands in loop like:

for i from 1 by 1 to k  do r:=Search(polyQ[i],[Q]) and T[r]:=T[r]-polyeq[i] end do

But Maple: "Error, unterminated loop". Hmm...

AoA. How are you? Hope you will be fine. I want write the following in Loop for any M


F[r,s]:=2^(k+2) m sqrt((c[r-1])/(c[s-1])) for r=2...(M+1), s=1..r-1 and (r+s)=odd;

F[r,s]:=0  otherwise



In Maple, I want to define a set of functions by means of two for loops:


    # Node coordinates.

    # Partition of unity.
    for j from 2 by 1 to N_x-1 do
        for k from 2 by 1 to N_y-1 do

However, this gives output in which the `[j,k]` vary but the `x_n[j-1]`, `x_n[j+1]`, `y_n[j-1]` and `y_n[j+1]` are not evaluated. But if I for instance input `x_n[3]` I correctly get 1/2 as answer.

How do I solve this?

Hi there,

first post. I am a beginner both with Maple and this forum, so please forgive my mistakes. Just here to learn.

I could not successfully use the Maple editor here, so the code goes as plain text, although I also attach the code:

I am trying to simulate the function below for certain values of the parameters, but when executing the loop, Maple prints just R. Can anyone tell me where my error is, please?


f := .25; g := 1; R[0] = 5; R[1] = 4.8; nDays := 30;

lambda1:=(1 - f + sqrt((1 - f) + 4*g*f)*1/2;

lambda2:=(1 - f - sqrt((1 - f) + 4*g*f)*1/2;

       -lambda2*R[0] + R[1]
       lambda1 - lambda2

       lambda2*R[0] - R[1]
      lambda1 - lambda2

R:=n-> k1*lambda1^n + k2*lambda2^n

for n from 2 to nDays
do R:=evalf(subs(n=%,R));


I wnat to print the polar that contain a part of loops,but it always contains all loops.

how do I solve this preblem?

Any one can help me,please?





i want to define a loop for like this : 

for i from 0 to 100 by 0.2 do; ... ; od ;

i want when this loop finishes,the the loop turns to exactly vice versa respect,and continue , i mean it continue like this :
for i from 100 to 0 by -0.2 ...  , 

can anybody help me to find an algorithm for this ? tnx in advance


So I wrote this script (30 lines) in Maple and it works fine. But now I want Maple to repeat the script while changing my input variable.

My variable is T and I want Maple to perform the script for T=0 to T=15 and with a step size of 0.1.


I tried for loop and proc, but could not make it work. What is the most appropriate way do this?


Thank you.




Hello everybody,


I have to solve a non linear equation using a numerical method. I use a loop after each iteration, Maple keep the results in memory instead of release their in variable. So calculation time is very long and the memory goes up.

Could you help me to improve the calculation time ? In fact, I would like to store results in a list and maple erases each intermediate results.


Thank a lot




matlab has break point in loops which in extremely useful tool for finding errors in long term loops,whay maple does not has sth similiar !?

I'm running a long loop with a lot of variables. I have noticed that Maple does not seem to clear its memory after each loop iteration, which results in very large memory used after all the iterations. I can't use restart because I need a few variables to be remembered throughout the loop for analysis afterwards. So the question is how to clear the memory for selective variables and procedures at the end of each iteration.


Suppose we have a vector as follows:


Could anyone help me to reproduce the following vectors via a "for" loop?

[ v, u, w, x, y, z]

 [ w, v, u, x, y, z]

 [ x, w, v, u, y, z]

 [ y, x, w, v, u, z]

I have a simple Matlab script which can do what I intend. So, my question is how can I implement this script in Maple?


for i=2:5

    Plex=[Plex(i) Plex];





Thanks in advance.


Could anyone help me to convert the following codes into Mpale?

while n>= 1
    for i=1:n
        S(i)=resultant(F(i), F(i+1), Plex(i));

Thanks in advance.


I have written a for-end loop and put all the outcomes of the loop in a matrix and now I want to plot these results but for some reason maple won't plot the matrix in a correct way. If I copy-paste the matrix into an new file maple plots it correct. What is the reason that maple won't plot it in my original file?

Here is my file. 

L := 20; Q := 20; n := 8; h := 3; EAv := 1;
Mat := Matrix(10, 2, storage = sparse);
a := 1;
loop L1
for L1 from .6 by .1 to 1.5 do
L1 := L1;
L2 := 2*L1;
L3 := 1.6*L2;
L4 := (1/2)*L-L1-L2-L3;
alfa1 := evalf(arctan(h/L1));
alfa2 := evalf(arctan(h/L2));
alfa3 := evalf(arctan(h/L3));
alfa4 := evalf(arctan(h/L4));
F4 := (1/2)*Q*L4;
F3 := (1/2)*Q*L3+(1/2)*Q*L4+F4;
F2 := (1/2)*Q*L2+(1/2)*Q*L3+F3;
F1 := (1/2)*Q*L1+(1/2)*Q*L2+F2;
w1 := evalf((1+sin(alfa1)^3)*F1*L1/(EAv*sin(alfa1)^2*cos(alfa1)));
w2 := evalf((1+sin(alfa2)^3)*F2*L2/(EAv*sin(alfa2)^2*cos(alfa2)));
w3 := evalf((1+sin(alfa3)^3)*F3*L3/(EAv*sin(alfa3)^2*cos(alfa3)));
w4 := evalf((1+sin(alfa4)^3)*F4*L4/(EAv*sin(alfa4)^2*cos(alfa4)));
kkm := (w1-w2)^2+(w2-w3)^2+(w3-w4)^2; Mat(a, 1) := L1;
Mat(a, 2) := kkm;
a := a+1
end do;



I  often find mself in the following quandry: I am investigating a problem, I do a few examples, run a do loop for j from1 to 5 to see if that works and then enter

for j from 1 to 200 do  a[j]:=blah, blah,...  end do:

and 15 minutes later nothing has happened. Is the loop finishing up with j = 198 or so or is it stuck at j = 23 and it will take forever to finish? Or perhaps there is an error that turns up for j > 23?

When I think about it I can insert a print(j) command to keep track of this but there are other situations where that doesn't work. For example,

Order := 35; mtaylor(....

When nothing happens is that because the calculation is almost done? or stuck? etc.

Is it possible to take a quick peek at the state of Maple and the decide whtether to continue the computation or abort? If the calculation of mtaylor(... is particularly long I might settle for the 15 coeficients computed so far rather than abort. Can I get at those?

Any advice?



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