Items tagged with loop loop Tagged Items Feed

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 

Hi so im trying to create a loop which allows me to find the first square after this number 
zahl:=1234567: could you guys tell me whats wrong and explain me why it is wrong, i suck at this :/

thank you so much 

zahl:=1234567:
 while sqrt(zahl)<> round(sqrt(zahl)) do  
   zahl:=zahl +1  
     if sqrt(zahl)<> round(sqrt(zahl))then  
  print(zahl):  
 end if:
 end do;

Here is a simple program that displays the issue.

yint:=proc(i,a,b) local y,yi; y:=x^i; yi:=int(y,x=a..b); return yi; end:

n:=10^4;

for i from 1 to n do inty:=yint(i,a,b); od:

Running the program gives the following memory usage.

n            memory
10^4      70M
10^5      138M
10^6      562M

Why is the memory increasing so much? Are internal variables to yint stored between calls?

How can I avoid the memory increase with such a loop?

Thanks.

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 

km:=
proc(n::TYPE1,m::TYPE2)
description "km(n,m) returns the sum of k^m as k ranges from 1 to n.";
---MORE STUFF HERE---
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.

Commutator_for_Infinitesimal_Generators_for_variable_coefficient_Zakharove_Kuznetsov_Equation.mw

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,
question.mw

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

 

 

``

 

Download question.mw

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
X[i,0]:=0;
Y[i,0]:=0;
   for j from 0 to N do
   if j=1 then X[i,1]:=1; Y[i,1]:=0;
    elif j>1 then
      r:=R3();
        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;
   R[i,j]:=[X[i,j],Y[i,j]];
   K[i,j]:=[X[i,j],Y[i,j]];
  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
    R[i,j];
    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;
     L[i,j]:=R[i,j];
     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!

Hello,

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 

with(LinearAlgebra);

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.

N:=10

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 

 

f:=x*cos(x)-sin(x)*sin(x/1000);
/ 1 \
x cos(x) - sin(x) sin|---- x|
\1000 /

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

j:=1:
for i from 0 to i_max by 1 do
x0:=x_min+i*step;
x[j]:=fsolve(f=0,x=x0);
j:=j+1;
end:

 

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:

...

Q(3,3)=2*Q(3,3);

 for i=1:length(R)

    T(1,1)=cos(R(i))^2; 

    T(2,2)=cos(R(i))^2; 

    T(1,2)=sin(R(i))^2; 

    T(2,1)=sin(R(i))^2; 

    T(3,1)=-sin(R(i))*cos(R(i)); 

    T(3,2)=sin(R(i))*cos(R(i)); 

    T(1,3)=2*sin(R(i))*cos(R(i)); 

    T(2,3)=-2*sin(R(i))*cos(R(i)); 

    T(3,3)=cos(R(i))^2-sin(R(i))^2;

    T1(1,1)=cos(R(i)); 

    T1(1,2)=-sin(R(i)); 

    T1(2,1)=sin(R(i)); 

    T1(2,2)=cos(R(i));

    

    Qk(:,:,i)=inv(T)*Q*T; 

    Qk(:,3,i)=Qk(:,3,i)/2; 

    Qk1(:,:,i)=inv(T1)*Q1*T1;

    A=A+Qk(:,:,i)*(h(i+1)-h(i)); 

    B=B+.5*Qk(:,:,i)*(h(i+1)^2-h(i)^2); 

    D=D+1/3*Qk(:,:,i)*(h(i+1)^3-h(i)^3); 

    A1=A1+Qk1(:,:,i)*(h(i+1)-h(i));

end

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.

ni:=2;
nj:=3;

writeto(`outfile`);

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

writeto(`terminal`);

mat:=Matrix(ni,nj);

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?

Thanks.

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.

BD_collapse_2.mw.

 

Hello,

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

  i+n

  end do

end do;

 

 

Regards

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