how could i use the while statement more faster

if any one please could help me with this. I'm making a loop using while statement , but it took too much time. is there is any way to reduce the needed time ?

댓글 수: 1

Jan
Jan 2012년 7월 21일
It is impossible to suggest an improvement without seeing the code. Please add it to the question by editing.

댓글을 달려면 로그인하십시오.

답변 (1개)

George Papazafeiropoulos
George Papazafeiropoulos 2012년 7월 21일

0 개 추천

What do you want to do exactly inside this while loop? Can you show some piece of code?

댓글 수: 3

well with this code i'm tryinf to find the solution of 2 equations in 2 variaples
the first equation is Mcc+Mct+Ms-M= 0 the seconed one Cc-Cct-Ts=0
the first variple is eps and the second one is x
i know there is a way to solve equations directly in matlap but these equations are a little complicated so when i try to solve them they give no ansewer.I try to do that using "solve" and "fmin" both of them fails to find the solution so i tried numirically. What is starnge that the same code i made in VBA and it works very fast, i don't know whay Matlab take so much time
here is the code
ep1=0;
ep2=epult;
eps=(ep1+ep2)/2;
x1 = 0;
x2 =h;
x = (x1+x2)/2;
run('C:\hattab\hattab\master of scince\my master\matlab\using matricies\Force.m');
while abs(Mcc+Mcct+Ms-M)/M>eqTol
if Mcc+Ms+Mcct-M>0
ep1=ep1;
ep2=eps;
eps=(ep1+ep2)/2;
else
ep1=eps;
ep2=ep2;
eps=(ep1+ep2)/2;
end
x1 = 0;
x2 =h;
x = (x1+x2)/2;
run('C:\hattab\hattab\master of scince\my master\matlab\using matricies\Force.m');
while abs(Cc-Ts-Cct)/Cc >eqTol
if Cc-Ts-Cct>0
x1=x1;
x2=x;
x=(x1+x2)/2;
% clac force
run('C:\hattab\hattab\master of scince\my master\matlab\using matricies\Force.m');
else
x2=x2;
x1=x;
x=(x1+x2)/2;
% clac force
run('C:\hattab\hattab\master of scince\my master\matlab\using matricies\Force.m');
end
end
end
thanks for your effort
Jan
Jan 2012년 7월 21일
Do not overwrite the built-in function eps with a local variable.
Add the folder "C:\hattab\hattab\master of scince\my master\matlab\using matricies\" to the path (see e.g. addpath) and call the script Force directly without the run command. It would even better to convert Force to a function.
it works thanks very much for your help

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2012년 7월 21일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by