Items tagged with loop loop Tagged Items Feed

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

 

 

[carré]NewmarkAlgo2FCzAlp.mw

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.

Hello;

Suppose we have a vector as follows:

Plex:=[u,v,w,x,y,z]

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?

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

for i=2:5

    Plex=[Plex(i) Plex];

    Plex(i+1)=[];

    disp(Plex)

end

 

Thanks in advance.

Hi;

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));
    end
    F(i)=S(i);
    n=n-1;
end

Thanks in advance.

Hi,

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. 

restart;
Parameters
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;

with(plots);
pointplot(Mat);

 

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?

 

 

AOA... Pl correct it

Help.mw

How can I write a general procedure which will take an integer n and create n nested loops:

add(...(add(f(x_1,...,x_n),i_1=0..k_1),...),i_n=0..k_n);

Thank you in advance.

Hi, 

 

I wish to be able to calculate the roots of the function f(p) by using the roots of the function h(p) and applying the bisection method due to the fact that the roots of h(p) bracket the roots of f(p) as can be seen in the graph below. I have done this before for another example when h:=J0(p); and hence i could use The commands BesselJZeros(0,n)/BesselJZzeros(0,n+1) to find the roots. So my problem arises with the finding the roots of h(p) and how to insert them into my bisection loop(underlined below).

Any advice would amazing. Many thanks


restart;

Digits := 30:
with (plots):
with(RootFinding):

#Define given parameters

R:=1: #external radius of particles, cm

d:=10^(-3): #diffusivity cm^2 per second

alpha:= 1: #fractional void volume

c0:=10^(-6): #concentartion of soltion in void volume of solid initially, moles per liter

C0:=0: #concentration of main body of solution initially, moles per liter

k1:=0.5: #constant in adsorption isotherm (ka)

k2:=0.75: #constant in adsorption isotherm (kd)

k:=2.5: #equilbrium constant for adsorption kinetics

n0:=(k1/k2)*c0:#initial amount absrobed on solid, moles per liter

V:=0.1: #volume of external solution, liters

W:=0.1: #weight of absorbant, grams

rho:=2.0: #solid aparrant density, g/cc

delta:=(1/d)*((p+alpha*k2+k1)/(p+alpha*k2));

beta:=W*alpha*d/(rho*V);

   

1000*(p+1.25)/(p+.75)

 

0.500000000000000000000000000000e-3

 

 

 

 

 


f:=p->(BesselJ(0,R*sqrt(-delta*p))*k*p-(R*sqrt(-delta*p))*BesselJ(1,R*sqrt(-delta*p))*(d*p/R + 2*beta*k/(R^2)));

proc (p) options operator, arrow; BesselJ(0, R*sqrt(-delta*p))*k*p-R*sqrt(-delta*p)*BesselJ(1, R*sqrt(-delta*p))*(d*p/R+2*beta*k/R^2) end proc

(2)

h:=p->(BesselJ(0,R*sqrt(-delta*p)));
plot([f(p),h(p)],p=-0.3..0,axis=-5..5,legend=["f(p)","h(p)"]);


 




proc (p) options operator, arrow; BesselJ(0, R*sqrt(-delta*p)) end proc

 

 

 

(3)



points:=5:
rts:= Array(1..points):
for n from 1 by +1 to points do
pl:=evalf(#**first root of h**);
pu:=evalf(#**second root of h, i.e n+1 root**);
pe:= (pl+pu)/2;
while abs(f(pe))>10^(-6) do
pe:=(pu+pl)/2;
if f(pu)*f(pe) <0 then
pl:=pe;
elif f(pl)*f(pe)<0 then
pu:=pe;
end if;
od;
rts[n]:=pe;

od;
rts[n]:=p[n];

 

 

Download spherical_continue.mw


 

Download spherical_continue.mw

Hi Maple Prime-ers!

I have a question about efficiency.  I have a set of algebraic equations with some polynomials, that I would like to solve at different points.  I've tried using a for-loop and a map-loop.  Here is a example:

 

n:=10000;  #Number of solving points
eq1:={b = ''a^2'', c = b^3/2, d = c^(1/2)*4 + b^2}; #Equation to solve

a := convert([seq(i,i=1..n)],Vector);  #timesteps

ans := Vector[column](n)

## Try solving in a for-next loop
t1 := time():
for q from 1 to n do
ans(q):=solve(subs({'a' = a(q)},eq1)):
od:
t2 := time() - t1;

## try solving in a map loop
t1s := time():
ans_s := map(q->solve(subs({'a' = a(q)},eq1)),a);
t2s := time() - t1s;

On my computer (2.2Ghz, 2 cores), these both take 115s to solve.  Using Map over For-Next did not speed up computational speed.  

The problem I wish to tackle has 12 equations, invovles 5th order polynomials, and n ~= 300000.  Solving this set of equations takes 2-3 hours.

Anyone know a more efficient method?  Thanks for reading :D

 

I have an Array that has both floats and pi and e expressions mixed in.  Would like to scan the Array and print the non-floats to the screen.

My if then statement works until I put it into a loop then I get no output.  Puzzled...

> hits := identify(d);
> for i from 1 to 501 do if type(Hits[i], 'float') = false then Hits[i] end if end do;

Hello everyone,

restart:with(plots):

xNData := ExcelTools:-Import("D:/a.xls"):

L := convert(xNData, listlist);

L := [[1.0, 0.75e-1], [2.0, .1], [3.0, .12], [4.0, .14], [5.0, .16], [6.0, .18], [7.0, .2], [8.0, .22], [9.0, .24], [10.0, .26]]

In the above L for each x we have N. I want to sub a single set of value [x,N] into THE equation NN to get a value for d and repeat the same process for each set of [x,N] to get d.  

NN := -N+(N0B-NB)*(erf((1/2)*x/(sqrt(t)*sqrt(d)))-sqrt(erf((1/2)*alpha/d)))/sqrt(erfc((1/2)*alpha/d))+NB;

alpha:=2*10^(-12):NB:=0.075:N0B:=0.2:t:=360000:

Cheers.

@Care Love, sorry for the trouble. I have edited the question.

a.xls

 

Hello,

restart:

N := N0-(1/2)*sqrt(2)*sqrt(Pi*Kc/d)*(sum(erfc((1/2)*(L*n+x)/sqrt(d*t))+erfc((1/2)*((n+1)*L-x)/sqrt(d*t)),

n = 0 .. infinity));

N0:=0.2:L:=0.25:Kc:=2*10^(-12):t:=360000:d:=2.010619298*10^(-10):

When I plot N vs x = 0..0.25 then there is no issue

plot(N,x=0..0.25,axes=box);

but when try to use a loop to get the data, Maple cannot evaluate

for x from 0 to 0.25 by 0.01 do

N[x]:=evalf(N0-sqrt(Pi*Kc/(2*d))*sum(((((erfc((n*L+x)/(2*sqrt(d*t))))+erfc(((n+1)*L-x)/(2*sqrt(d*t))))),n=0..infinity)));
end do;

Thanks

  

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?

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