Items tagged with while

I want to use while in proc but Maple shows an error saying

 

"Error, (in exa) illegal use of a formal parameter"

 

When I click on it, as usual it says "There is no help page available for this error". I tried a very simple example of while which you can see it below and it again shows same error. The while works well but when I put it inside of a procedure it makes an error. Note: the following example is just an example, this is not what I'm doing so please don't reply this while proc is not giving anything. My question is how can I use a while in procedure without encountering the above error.

 

i := 10;
while i > 1 do
if i mod 2 = 0 then i := i/2; else i := i+1; end if;
end do;

 

Now with proc

 

exa := proc (i::integer)::integer;
while 1 < i do
if i mod 2 = 0 then i :=i/2; else i := i+1; end if
end do; 
end proc;

exa(10);

"Error, (in exa) illegal use of a formal parameter"

Hi, all. I need to built a user interface for my program. First, I create two label and two text area for both the value of x and y. After that I assign a button to random generate the value for x and y within the range with x <y. I write the code below into click action of the button.

use DocumentTools in

Do(%x=RandomTools[Generate](integer(range=1..7);

Do(%y=RandomTools[Generate](integer(range=1..7);

while %x>= %y do

Do(%x=RandomTools[Generate](integer(range=1..7);

Do(%y=RandomTools[Generate](integer(range=1..7);

end do;

end use;

This code can generate two random number and insert inside the boxes created. When the button is clicked, two random number generated but the error dialog box shown on the screen with message : Error in component button with caption "generate" cannot determine if this expression is true or false: %y=%x. What I want is only the true value of x<y will be inserted to the text boxes. 

Any suggestion? Any help will be highly appreciated. Thank you.

 

I need to write a procedure that does the following :

Write a procedure quadsum whose input is an integer n and whose output is a list of pairs of solutions [x,y] to the above formula.

Your procedure should implement the following algorithm.

1 Initialization
Set
"mylist = []."

Start at
x = 0
and
y = 0.

2 Phase A
Increment both
x
and
y
until
"x^2+y^2 >=n."

Phase B
Repeat the following until
x^2>n

If you are above the circle
x^2 + y^2 = n
then go down in unit steps until you are on or below the circle.

If you are on the circle, add the point to the list
"mylist. "

If you are on or below the circle
x^2 + y^2 = n
then go one step to the right. My procedure is as follows: but it runs into an infinite loop(most probably because of the while loop defined inside the while loop). What am I doing incorrectly?

I have atta

 

Hi,

I'm currently writing a programme for synchronising automatas, its creates an array and adds words or matrices to the array that aren't already in. I am currently getting an error when i try and run my procedure though and i'm unsure of the problem, any help would be appreciated, here is my code so far.

Thanks!

proc_cerny1:=proc(A::Matrix,B::Matrix,C::Vector[row],N)
local x, S, i, j, T, R, y, found;
x:=2^N;
S:=Array(0..(x-1));
S[0]:=C;
i:=0;
j:=1;
found:=false;

while (i<(x-1) and i<>j) do
T:=S[i].A;
for y from 0 to j do
if LinearAlgebra:-Equal(S[y],T) then
found:=true;
if (found=false) then
S[j]:=T;
j:=j+1;
end if:
end if:
od:

R:=S[i].B;
for y from 0 to j do
if LinearAlgebra:-Equal(S[y],T) then
found:=true;
if (found=false) then
S[j]:=R;
j:=j+1;
i:=i+1;

end if:
end if:
od:
od:
print(S);
end proc:

 

The error i'm getting is when i input this:

proc_cerny1(Matrix([[1,0,0],[1,0,0],[1,0,0]]),Matrix([[0,1,0],[0,0,1],[0,0,1]]),Vector(1..3,1,orientation=row),3);

and the error is:

Error, (in LinearAlgebra:-Equal) invalid input: LinearAlgebra:-Equal expects its 1st argument, X, to be of type {Matrix, Vector} but received 0

 

Hi all,
I've got this code but the second if statement does not seem to work within the for cycle... If I write it outside the cycle it works... Can you help me with this??? 
 
Dec := {1, 4}; Var := {2, 3, 5, 6}; n[1] := 4; n[2] := 3; n[3] := 2; n[4] := 3; n[5] := 4; n[6] := 2; Ut := {1, 2, 3}; pa[2] := {1}; pa[3] := {1, 2}; pau[1] := {3}; pa[5] := {4}; pau[2] := {5}; pa[6] := {4, 5}; pau[3] := {4, 6}; J := {3, 5, 6};
m := numelems(Ut); n := numelems(`union`(Dec, Var)); j := numelems(J);

if member(n, J) then A[n] := {`union`(pa[n], `intersect`(pau[3], {n}))}; jcur := j-1 end if

for i from n-1 to 1 do if member(i, J) then A[i] := `union`(`union`(A[i+1], pa[i]), `intersect`(pau[jcur], {i})); jcur := j-1 else A[i] := `union`(A[i+1], `intersect`(pa[i], {i})) end if end do

Thanks in advance
manuele

Or I didn't get something right? This is with Maple 16.02 on a Mac:

maple worksheet snapshot

 

> for i from 1 to 10 while i<=5 do print(i) end do; #works all right
> for i from 1 to 10 while i>=5 do print(i) end do; #nothing shows up?

I am trying to work with a for do loop with a while component. I have the error but I am not sure what the desired error should be. I know it has to be small but how small?

 

Thanks

here is my maple procedure. I have to make the iteration works until I have met the initial condition it will stop. the initial conditions here is z:=ic.


Say I wanted to print out all values from 1 to 8 but excluding 3, how would I do that using a for loop?

For example, this just stops after 2:

for i to 8 while i <> 3 do
print(i);
end do ;

whereas I want it to skip 3 so going 1,2,4,5,6,7,8.


For what I'm actually doing, I need i to run over a range but excluding one value.

 

Thanks!

 

Hi,

statements

I only want to display 'position' in animation while tend <= 12:
This is the trial:

restart:with(plots):
for tend from 0 to 50
while (tend <= 12) do
pos:=animate(textplot3d,[[-1.8,0,alpha*tend, 'position']], tend=0..50,frames=150);
od;
display(pos);


I receive error messages:
error, (in plots/animate) 0=0..50 is an invalid animation range

 

Then I try:

restart:with(plots):
while (tend <= 12) do

Hi I've been searching for an example of a while loop (no recursion) with 2 parts to it, but I have not been able to find one.  Does anyone know of any or can make one up for me?  Thanks!!!

Page 1 of 1