how to iterate until the difference between variable is equal to zero

8 vues (au cours des 30 derniers jours)
SITI AISHAH
SITI AISHAH le 28 Mar 2019
Commenté : SITI AISHAH le 29 Mar 2019
tf = 140
V = (1.5800e-08)*exp((1.1575e+03)/(tf + 95))
S = (625)^2*((V*(N/60))/160)
delta_T = (0.349109 + (6.0094*S)+(0.047467*(S^2)))*(160)/9.7
t_ave = 120 + (delta_T/2)
tff = (tf + t_ave)/2
delta = tf-t_ave
while tf-t_ave >0
tf = tff
t_ave = 120 +(delta_T/2)
end
i want to make the value of tff as the new value for tf and keep on until tf and tff got the same value of number.
  2 commentaires
Alex Mcaulley
Alex Mcaulley le 28 Mar 2019
N is not defined. By the way, your while loop never finishes (tf - t_ave have allways the same value), unless
tf <= t_ave || tff <= t_ave
What do you exactly want to do? Because the answer to your question is trivial:
tf = t_ave
tff = t_ave
And no while loop is needed.
SITI AISHAH
SITI AISHAH le 28 Mar 2019
Modifié(e) : SITI AISHAH le 28 Mar 2019
hi alex, I want to do iteration as in the figure attached. I want to stop the iteration once the difference between tf and t_ave had become 0. I also want to make tff value as the new tf and keep iterate until both of them got the same number and that will make difference between tf and t_average as 0. btw , tf > t_average and that's why i want to iterate until they become 0.

Connectez-vous pour commenter.

Réponse acceptée

Alex Mcaulley
Alex Mcaulley le 29 Mar 2019
The iteration is not clear. You need to update the values of tf and t_ave inside the while loop. I guess that is an optimization problem and you want tf-t_ave = 0, and following your image I can see that tf is updated in each iteration by
tf = tf - (tf-t_ave)/2
There aremore efficient options for optimization problems than this while loop, but the code that implements the iterations you have in the image is as follows:
tol = 1e-2;
tf = 140
N = 1.7501e+03;
V = (1.5800e-08)*exp((1.1575e+03)/(tf + 95))
S = (625)^2*((V*(N/60))/160)
delta_T = (0.349109 + (6.0094*S)+(0.047467*(S^2)))*(160)/9.7
t_ave = 120 + (delta_T/2)
% tff = (tf + t_ave)/2
while abs(tf-t_ave) > tol
delta = (tf-t_ave)/2;
tff = tf;
tf = tf-delta
V = (1.5800e-08)*exp((1.1575e+03)/(tf + 95));
S = (625)^2*((V*(N/60))/160);
delta_T = (0.349109 + (6.0094*S)+(0.047467*(S^2)))*(160)/9.7;
t_ave = 120 + (delta_T/2)
end
  1 commentaire
SITI AISHAH
SITI AISHAH le 29 Mar 2019
Hi Alex. This is such a big help for me. I've tried your code and its working. Thank you so much. I appreciate it as I'm new in using MATLAB. Thanks again :)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Computer Vision with Simulink dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by