Items tagged with loop loop Tagged Items Feed

so I'm trying this:

restart;

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/`σ_x`^2)/sqrt(2*Pi*`σ_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, `σ_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]

...

V[n]

with type of V[i] is a array.

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

V_matrix:=<V[1],V[2],V[3]>

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

(1)

``

 

Download idempotency.mwidempotency.mw

 

 

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:

rows:=RowDimension(subsMatrix);

columns:=ColumnDimension(subsMatrix);

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

                 subsEquations[i]:=equations

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

                     else      

                          #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?

Thanks.

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
        A:=DeleteColumn(A,i);
    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.

Hello,

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^2
od;

i; --> 5

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

Thanks a lot for your help.

 

the expression

sN=a1+a2+...+aN

for k from 1 to N do

psum=psum+a(n);

end do;

s[k]:=psum;

end do:

 

how do we transform this using only one loop?

 

thanks

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  

`tile2__j,k`:=dellT/(h^(2))*(`tile__j+1,k`-4*`tile__j,k`+`tile__j-1,k`+`tile__j,k-1`)+`tile__j,k`  

 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?

 

Dear All

Please see following:

 

Suppose we have

M := proc (i) options operator, arrow; i/(i+1) end proc

proc (i) options operator, arrow; i/(i+1) end proc

(1)

and

F := proc (i, j) options operator, arrow; M(i)/(M(i)+j) end proc

proc (i, j) options operator, arrow; M(i)/(M(i)+j) end proc

(2)

 For i from 1 to 5 and j from 1 to 5, how one can display all values of F(i,j) using "loop" ???

 

Download loop.mw

Regards

I want to plot a function given different value combinations of parameters. I used the following code and it doesn't work. Could anybody please help?

I'm new to Maple, and I come from using Matlab.  Apparently my Matlab way of thinking isn't working on Maple.  I'm trying  to ride a bit of code that simulates flipping a coin 1000 times.  The code counts one partiuclar result (1=heads) at the end prints that result.

 

Here's the code:

 

dice:=proc()

count:=0:  

for i from 1 to 10000 do  

roll := rand(1..2):  

roll:=()  

if (roll=1) then count:=count+1 end if  

end do  

print(count)  

 I get errors saying I didn't terminate my loops correctly.  Help, please.

I have a homework ask you to find the first string of (at least)10, 50, 100 consecutive composites. I have no idea how to use maple. HELP

all i can think of is 

 

>ithprime(i+1) - ithprime(i) = 10

>print(i+1, i)

 

and combine it with some loop

i dont know how to set up a loop

 need a lot of help 

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