Items tagged with loop

When I write an conditional command I come back and press enter again and again but I need only last one for example 




>if f(x) <g(x) then;

>x:=x+1 elif f(x) >g(x) then;

>y:=y+1 elif f(x)=g(x) then;



>f(x) end if;

I push enter and it write x:=1 then I click if command and push enter again and it writes x:=2 and continues like y:=1, x:=3, y:=2, x:=4,  y:=3 and lastly 




But I only need last one. Can I do this only push enter once. Of course my problem is more complicated than this f(x) , g(x) . Thanks




i have to develop a code i which i have system of nonlinear equation 

i have to generate the matrix of that nonlinear equation then i want to do or apply any method say newton method and make a loop which help us to find a solution using some tolerance 

at the end i get a result in form of a table which give nth matrix then value of function matrix at nth value then error i-e xn-x(n-1) 

thanx in advance

I need to write a procedure that adds all multiples of 5 and 7 less than an arbitrary number. I was thinking something maybe with mod? I am very new to Maple. 


On in this same assignment, we are also supposed to generate a sequence using the Fibonacci equation but from an arbitrary pair of initial conditions. So if there are some parallels between these two problems, I would love to learn from that angle.  

We recently in class learned about do loops, so if there is a way to attack these problems with do loops, I would like to hear!


I wonder if there is a way to see the progress of a specific procedure.  I have checked the forum for some answers and found that some of them propose a progress bar. However the progress bar doesn't seem to fit within a procedure.   

I don't need anything fancy but I need to see the progress of the loop inside of the procedure (over 3,000,000 times).   

Any suggestions?   

Many thanks


PS. I am running Maple 2016 too but I would rather see a solution that works on Maple 14 too, if possible.

so I'm trying this:


sigma := 0.143e-18;

l_0 := 1.87;

l0 := 1.87;

roll := rand(0 .. 25.0);

f_gauss := proc (x) options operator, arrow; exp(-(1/2)*x^2/`&sigma;_x`^2)/sqrt(2*Pi*`&sigma;_x`^2) end proc;

f_norm := proc (dx) options operator, arrow; int(f_gauss(x), x = -(1/2)*dx .. (1/2)*dx) end proc;

sol_gauss := proc (mix) options operator, arrow; evalf(eval(-ln((int(f_gauss(x)*exp(-2*sigma*N2O*sqrt((1/4)*l_0^2-x^2)), x = -(1/2)*dx .. (1/2)*dx))/f_norm(dx))/(sigma*N2O), [N2O = 0.25e20*mix/100])) end proc;

for ii to 10 do

a := roll();

eval(sol_gauss(a), [dx = l_0, `&sigma;_x` = l0])

end do

I'd like to find out what number Maple can still calculate the isprime for, and what number will make it go "No thanks, this is madness - ERROR".

I tried isprime (10100,000,000 + 2), and it can still calculate the result. No prime of course, that's the whole point of the +2.

I tried isprime(1010ˆ9 + 2) and it crashed.

But what is the tipping number?

I decided I should write a loop, and let maple write away the last number till it crashes. Is this possible? I think I'll need something like

> for n from 5 to ??? do isprime (10ˆn + 2) and ??? end do

This isn't suitable at all, but I cant figure out how to program "to error" or "write away this number"...


I hope the question is clear and look forward to ideas on how to make this work.


Dear Pros, I'm a biginer so I have a question about my program.

I have a lot of arrays which are result from 2 while loop. Now, I want creat a matrix from them but i can't. So, could you help me to do it.

For detail: 

V[1]:=[ 1 2 3]

V[2]:=[2 3 4]

V[3]:=[3 4 5]

V[4]:=[2 6 7]

V[5]:=[7 8 9]



with type of V[i] is a array.

I searched and found a solution by manual to create a matrix as follow:


but in this case i can't but manual with n=100

please help me to have a Matrix.

Thank a lots.

most effective built in operator code award goes to ppl that wrote the code for the union and intercect set operations for maple. Very important simple example below of  one of its applications.


When i work with algorithms, probably one of my most primary ports of enquiry (figuratively jeez skynet)  is to set up and if statement triggered to terminate the loop once the operations performed for any further cycles is INDEMPOTENT. this doesnt always mean your output is convergent in every case but it allows you to minimize the amount of time the cpu needs to collect data( ie the point at which it would produce that same set as it did in the last most loop)



Y := proc (X) local N, S1, `&Sopf;`; if X <> `union`(X, S1[N]) then N := (rand(1 .. NrANGE))(); S1[N] := {K[1](4+N), K[1](5+N), K[1](6+N), K[1](7+N), K[1](8+N), K[1](9+N), K[1](10+N), K[1](11+N), K[1](12+N), K[1](13+N), K[1](14+N), K[1](15+N)}; `&Sopf;` := `union`(X, S1[N]) else  end if end proc

proc (X) local N, S1, `&Sopf;`; if X <> `union`(X, S1[N]) then N := (rand(1 .. NrANGE))(); S1[N] := {K[1](4+N), K[1](5+N), K[1](6+N), K[1](7+N), K[1](8+N), K[1](9+N), K[1](10+N), K[1](11+N), K[1](12+N), K[1](13+N), K[1](14+N), K[1](15+N)}; `&Sopf;` := `union`(X, S1[N]) else  end if end proc







I have the following problem consisting of multiple seteps.

I have a vector equation consisting of n equations with n parameters (a[n]). Usually the n <= 15. As example data I will use the case n=4.

equations := Vector[column]([ a[1], a[2], a[3],a[4]])-Vector[column]([ b[1], b[2], b[3],b[4]])=0;

The first thing I want to create is a matrix with a format 2^n x n (here: rows=16 by columns=4). The matrix only consists of ones and zeros which contains all possible combinations of ones and zeros. E.G. for n=4

subsMatrix := Matrix([[ 0 , 0 , 0 , 0 ],[ 1 , 0 , 0 , 0 ],[ 0 , 1 , 0 , 0 ],[ 0 , 0 , 1 , 0 ],[0 , 0 , 0 , 1],[1, 1 , 0 , 0],[1, 0 , 1 , 0],[1, 0 , 0 , 1],[0, 1 , 1 , 0],[0, 1 , 0 , 1],[0,0,1,1],[1, 1 , 1 , 0],[1, 1, 0 , 1],[1, 0 , 1 , 1],[0, 1 , 1 , 1],[1, 1 , 1 , 1]]);

Question 1: How do I create such a matrix for the general case? I have absolutely no idea how to achieve this with Matple

The next thing I want to do is to use the rows as substitution equations for the a[i] values, only if the value of the subsMatrix is 0. E.G. in the first case I want to set a[1]=a[2]=a[3]=a[4]=0, then a[2]=a[3]=a[4]=0, then a[1]=a[3]=a[4]=0, and so forth and save the equation as a new equation

I tried the following:



for i from 1 by 1 while  i<=rows do


                 for j from  1 by 1 while  j<=columns do

                     if subsMatrix[i,j] =0 then

                          subsEquations[i]:= subs(a[j]=subsMatrix[i,j],subsEquations[i]) 


                          #do nothing if the value in the subsMatrix[i,j]=1

                     end if

                 end do:    

end do:

Question 2: What is my error? Maple says the loop is indeterminate. But I don't see why it is not working.


I would be thankful if someone could help me out. I am open to other kind of strategies to this problem :).

I am trying to do an hourly simulation of a solar-thermal system. The method I am using requires an inital guess for a value which is used in a series of equations. That variable is then back calculated, and checked against the initial guess. If it is too far off, the back calculated value is used as the new guess and so on...

My question is twofold. First, is there a way to create a sort of module that can execute a number of steps when called upon (i.e. the iterative process described above). Second, how can I run this for each hour of the year (the weather inputs for each hour will change) without manually executing each one, one at a time. So far my guess is to make a matrix with the weather inputs for each hour, and then have some sort of loop read the rows (hours) one at a time, pull the data from it, run the series of steps, and then store the output for that hour in a new matrix. Is this the best way to do this? If so, which functions/tools in Maple should I look into that can do this for me?


Hi there,
I have a simple task to do with arrays. I have an 8x3000 array, whose columns are sometimes all zeroes (if any element in the column is zero then the entire column is zero). I want to eliminate the zero vectors, so I have this loop (the array is A)

for i from 1 to 3000 do
    while A(1,i)=0 do
    end do;
end do:

Setting "A:=DeleteColumn(A,i);" reduces the size of the array, so if all the zero columns have been deleted at "i=200", Maple will keep trying to check the next column, which doesn't exist anymore. This gives an "index out of bounds" error, but also records "A" as the new smaller array, which is fine.

If I run this loop inside a procedure, the error stops the procedure, but it doesn't record the new array, it stays as the older, larger one. Does anyone know of a way around this?

Any help would be much appreciated.

Hi, I'm having trouble trying to make a loop stop when a variable hits certain value. No, break doesn't help much as the code is intended to be executed w/ "execute the entire worksheet" command, and break only stops the calculation on this especific execution block (I'm using maple 18 btw).

Any ideas would be highly apreciated.


I have a little question about the property "local" or not of a index in a for loop.

I notice that when I make "for loop" the index i is not local. In the small example, when I ask to evaluate i after having done this loop, the answer is 5 and not i.

Example :

for i from 1 to 4 do

i; --> 5

How can I do to ask Maple to use index as local ?

Thanks a lot for your help.


the expression


for k from 1 to N do


end do;


end do:


how do we transform this using only one loop?



So, I am working in a partial differeital equations course and we are doing image processing. I am taking an image and pixel by pixel applying the heat equation to smudge out noise. I created a for loop for the equation and it works, I need to itterate it over and over again. Here is my code:

for t from 1 to 20 do    

for j from 2 to 149 do

for k from 2 to 149 do  


 end do

end do  

for m from 2 to 149 do

for n from 2 to 149 do  

`tile__m,n`:= `tile2__m,n`  

end do

end do  

t := t+1  

end do


Sorry, I could not get the Maple Math editor to work so I just copied my code. Apologize. I keep getting the error "Error, Invalid loop statement termination." Help?


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