2 views (last 30 days)

Can anyone help me out with their past experience that how much time this below program will take approximately containing 6 for loops with each performing approx. 15 itterations.Matlab is utilizing 985 Mb of ram.

function o=optimum() m=[1,1.25,1.5,2,2.5,3,4,5,6,8]; %normal module from psg q=1; l=zeros(4500000,16); j1=input('\n enter j'); Pin=input('\ninput power'); ip=input('\n reduction'); N1=input('\n input speed'); sp1=700; sg1=300; Ep=205000; Eg=205000; BHN=300;

for w=9:1:23 %helical angle for gearpair 1

for g=2.1:0.3:8.1 %gear ratio for first gearpair

a=(2*(cos(w*pi/180)^3))/(sin(pi/9)^2); %condition for min no teeth on 1st pinion

t=ceil(a);

for t1=t:1:t+9 %no of teeth on first gear

t2=round(g*t1); %no of teeth on second gear

gmdf=t2/t1; %modified gear ratio of 1st pair

mt=m(1,1)/cos(w*pi/180);%transverse module of 1st pair

d1pcd=mt*t1;%pcd of 1st gear

d2pcd=mt*t2;%pcd of second gear

for i=1:1:10

for w1=9:1:23 %helical angle for gearpair 2

g2=ip/gmdf; %ip is the input gear reduction by user

c=(2*(cos(w*pi/180)^3))/(sin(pi/9)^2); %condition for min no teeth on 2nd pinion

z=ceil(c);

for t3=z:1:z+9 %no of teeth on 3rd gear

t4=round(g2*t3); %no of teeth on 4th gear

gmdf1=t4/t3; %modified gear ratio of 2nd pair t3; %

mt1=m(1,i)/cos(w1*pi/180); %transverse module of second pair

d4pcd=mt1*t4; %pcd of 4th gear

d3pcd=mt1*t3; %pcd of 3rd gear

v1=(pi*d1pcd*N1)/(60*1000); %N1 is the input speed by the user

v4=v1/(gmdf*gmdf1); %pitch line velocity of second gear pair

b1=ceil((1.15*pi*m(1,1))/sin(w*pi/180)); %face width first gear pair

if b1>15*m(1,1) && b1<9*m(1,1)

b1=round(10.5*m(1,1));

else

b1=ceil((1.15*pi*m(1,1))/sin(w*pi/180));

end

b2=ceil((1.15*pi*m(1,i))/sin(w1*pi/180)); %face width of second gear pair

if b2>15*m(1,i) && b2<9*m(1,i)

b2=round(10.5*m(1,i));

else

b2=ceil((1.15*pi*m(1,i))/sin(w1*pi/180));

end

fb11=sp1*b1*m(1,1)*(0.484-(2.87*cos(w)^3)/(t1)); % sp1 is bending stress

fb12=sg1*b1*m(1,1)*(0.484-(2.87*cos(w)^3)/(t2)); % fb is bending stress

if fb11>fb12

fb1=fb12;

else

fb1=fb11;

end

fb13=sp1*b2*m(1,i)*(0.484-(2.87*cos(w1)^3)/(t3)); %sp=ultimate tensile strength/3(of pinion)

fb14=sg1*b2*m(1,i)*(0.484-(2.87*cos(w1)^3)/(t4)); %sg=ultimate tensile strength/3(of gear)

if fb13>fb14;

fb2=fb14;

else

fb2=fb13;

end

q1=(2*t2)/(t1+t2);

q2=(2*t4)/(t3+t4);

k=(0.18)*(BHN/100)^2;

fw1=(d1pcd*b1*q1*k)/(cos(w*pi)/180); %fw is surface wear force

fw2=(d3pcd*b2*q2*k)/(cos(w1*pi)/180);

e1=(16+0.63*(m(1,i)+0.25*(d1pcd)^(1/2))+0.63*(m(1,i)+0.25*(d2pcd)^(1/2)))*0.001; %pitch error on meshing teeth

c1=(0.111*e1)*((Ep*Eg)/(Ep+Eg)); %Ep=modulus of elasticity of pinion and Eg=modulus of elasticity of gear

Ft1=1.25*1.5*(Pin/v1); %first factor of f effective and Pin=input power by user

Fd1=(21*v1*cos(w*pi/180)*(b1*c1*(cos(w*pi/180))^2+Ft1))/(21*v1+(b1*c1*(cos(w*pi/180))^2+Ft1)^(1/2));

Feff1=Ft1+Fd1; % effective force of first gear pair

e2=(16+0.63*(m(1,i)+0.25*(d3pcd)^(1/2))+0.63*(m(1,i)+0.25*(d4pcd)^(1/2)))*0.001; %pitch error on meshing teeth

c2=(0.111*e2)*((Ep*Eg)/(Ep+Eg));

Ft2=1.25*1.5*(Pin/v4);

Fd2=(21*v4*cos(w1*pi/180)*(b2*c2*(cos(w1*pi/180))^2+Ft2))/(21*v4+(b2*c2*(cos(w1*pi/180))^2+Ft2)^(1/2));

Feff2=Ft2+Fd2; %effective force on second gearpair

cd1=(d1pcd+d2pcd)/2;

cd2=(d3pcd+d4pcd)/2;

cd=max(cd1,cd2);

m1=m(1,i);

if fb1>Feff1 && fb2>Feff2 && fw1>Feff1 && fw2>Feff2

f.o.s1=(fb1/Feff1); %factor of safety for first pair (bending)

f.o.s2=(fb2/Feff2); %factor of safety for second pair (bending)

f.o.s3=(fw1/Feff3); %factor of safety for first pair (surface)

f.o.s4=(fw2/Feff4); %factor of safety for second pair (surface)

x=[f.o.s1,f.o.s2,f.o.s3,f.o.s4];

z=min(x);

if j1==1

u=1;

v=0;

l(q,:)=[m(1,1) w gmdf t1 t2 m1 w1 gmdf1 t3 t4 cd1 cd2 cd u v z];

q=q+1;

elseif j2==1

if z>r %r=fos given by user

u=1; %u=logical array for force

v=1; %v=logical array for fos

l(q,:)=[m(1,1) w gmdf t1 t2 m1 w1 gmdf1 t3 t4 cd1 cd2 cd u v z];

q=q+1;

else

u=1;

v=0;

l(q,:)=[m(1,1) w gmdf t1 t2 m1 w1 gmdf1 t3 t4 cd1 cd2 cd u v z];

q=q+1;

end

end

else

u=0;

v=0;

z=0;

l(q,:)=[m(1,1) w gmdf t1 t2 m1 w1 gmdf1 t3 t4 cd1 cd2 cd u v z];

q=q+1;

end

end

end

end

end

end

end

if j1==1

t=find(l(:,14)==1);

n=size(t);

for i=1:1:n(1,1)

t(i,1)=l(t(i,1),13);

h=min(t);

end

elseif j2==1

t=find(l(:,15)==1);

n=size(t);

for i=1:1:n(1,1)

t(i,1)=l(t(i,1),13);

h=min(t);

end

end

o=find(l(:,13)==h);

fprintf('\n %f',o(1,1));

end

Adam
on 23 Sep 2016

Edited: Adam
on 23 Sep 2016

If you are using R2016a (or maybe R2015b, I can't remember when it was introduced) there is now the very useful pause feature when running code so that you don't have to just sit there and wonder if your code will ever end, you can pause it and land in the code at the current point to see how far it has got.

On the same note, you could use a progress bar (e.g. waitbar, though I prefer to use one of the many alternatives in the file exchange) around one of your for loops. This will give you an indication of how fast your code is going although this again is an estimate that depends very much on the nature of your code.

I like to use this one personally

as it comes with an estimated completion time, but you must be aware that the estimate is based purely on what proportion it has done so far - e.g. if you update it in a for loop from 1 to 10 then when it gets to the end of iteration 5 it's estimate of time remaining will be roughly equal to the time it has spent so far. It does not know if, for example, each iteration of your code gets slower and slower, in which case its estimate of time remaining will keep rising even as it progresses.

If you think your algorithm is fairly linear in its progress then you can run it with this progress bar for a certain period and then get an estimate of how long the full program would take. Obviously the longer you let it run for the more accurate an estimate it would be.

Luuk van Oosten
on 23 Sep 2016

Dear Taher,

How long such a programm will take to run depends on many things (both you hardware & your software). But... you can simply test how long it will take by using the stopwatch

tic

your_program

toc

Luuk van Oosten
on 23 Sep 2016

Dear Taher,

This is [in general] impossible, as Adam has already said. You could time individual parts of your loops and make an estimated guess.

Even with the [very rough] knowledge of your hardware, there are many factors in play which influence run time. The best thing to estimate run time is.... experience. If I were you, I would just run the program with tic-toc. Start on Friday afternoon, go home, have a beer, and see Monday morning what has happened.

Sign in to comment.

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 1 Comment

## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/304174-estmated-time-required-for-my-following-program#comment_393074

⋮## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/304174-estmated-time-required-for-my-following-program#comment_393074

Sign in to comment.