How create a interaction method to re-calculate a equation if a condition is not satisfied

I have a equation where i need to input a value and calculate some equations with this value.
In the end, i need to check if this value is ok.
If it's not, I need to input a new value and calculate the equation again with this new value.
Somebody can help me?
I tried this way.
I need to input "Tin" and calculate "Tw". In the end, i need check if the average between Tw and "Tb" in less than 10%. If it's not i neet to input a new value for "Tave".
clear
close all
Tin=input('Input T');
D=5;
t=0.362;
E=2.9e07;
ws=17.9148297590378;
R=1448.88;
alfa=1.96;
h=R*(1-(cos(alfa/2)));
I=pi*(D-t)*(D-t)*(D-t)*t/8;
teta=19.45;
L=495.73;
conv=teta*pi/180;
mis=0.3;
mil=0.05;
DRAG= 12*pi*D*L*mil;
Tb=8.89e4;
G=Tin;
for i=1:100
G(i)=Tin(i);
J=sqrt(E*I/G(i));
U=12*L/J;
X=3*L-(J/2)*tanh(U/2);
Y=18*L*L-J*J*(1-(1/cos(U/2)));
N=(12*G(i)*h-(ws/12)*cos(teta)*Y)/X;
frictc=N*mis;
ter=ws*L*sin(conv);
deltac=2*frictc+DRAG-ter;
Tw=deltac+Tb;
Tave(i)=(Tw+Tb)/2;
if Tave(i)>G(i)+G(i)*0.1
G(i)=Tave(i);
elseif Tave2(i)<G(i)-G(i)*0.1
G(i)=Tave2(i);
else
display(Tave2(i));
end
end

2 comentarios

you have to enter new value for Tave or Tin? and also what is meaning of it " i need check if the average between Tw and "Tb" in less than 10%" less than 10% of which values ?
I'm sorry
New value for "Tin" if "Tave" is greater than 10% of "Tin".
Now the sentence is correct

Iniciar sesión para comentar.

 Respuesta aceptada

sixwwwwww
sixwwwwww el 9 de Dic. de 2013
Editada: sixwwwwww el 9 de Dic. de 2013
try this:
Tin=input('Input T');
D=5;
t=0.362;
E=2.9e07;
ws=17.9148297590378;
R=1448.88;
alfa=1.96;
h=R*(1-(cos(alfa/2)));
I=pi*(D-t)*(D-t)*(D-t)*t/8;
teta=19.45;
L=495.73;
conv=teta*pi/180;
mis=0.3;
mil=0.05;
DRAG= 12*pi*D*L*mil;
Tb=8.89e4;
G(1) = Tin;
for i=1:100
J=sqrt(E*I/G(i));
U=12*L/J;
X=3*L-(J/2)*tanh(U/2);
Y=18*L*L-J*J*(1-(1/cos(U/2)));
N=(12*G(i)*h-(ws/12)*cos(teta)*Y)/X;
frictc=N*mis;
ter=ws*L*sin(conv);
deltac=2*frictc+DRAG-ter;
Tw=deltac+Tb;
Tave(i)=(Tw+Tb)/2;
if Tave(i) >= Tin * 0.1
Tave(i) = input('Enter new value of Tave:');
end
G(i + 1) = Tave(i);
end
display(Tave(i))

6 comentarios

I think it works well
But now i see, that i need to use the value of "Tave" as the new "Tin" if the condition is not satisfied.
Or display the value of "Tave" if he is grather than 10%
try now:
Tin=input('Input T');
D=5;
t=0.362;
E=2.9e07;
ws=17.9148297590378;
R=1448.88;
alfa=1.96;
h=R*(1-(cos(alfa/2)));
I=pi*(D-t)*(D-t)*(D-t)*t/8;
teta=19.45;
L=495.73;
conv=teta*pi/180;
mis=0.3;
mil=0.05;
DRAG= 12*pi*D*L*mil;
Tb=8.89e4;
G(1) = Tin;
for i=1:100
J=sqrt(E*I/G(i));
U=12*L/J;
X=3*L-(J/2)*tanh(U/2);
Y=18*L*L-J*J*(1-(1/cos(U/2)));
N=(12*G(i)*h-(ws/12)*cos(teta)*Y)/X;
frictc=N*mis;
ter=ws*L*sin(conv);
deltac=2*frictc+DRAG-ter;
Tw=deltac+Tb;
Tave(i)=(Tw+Tb)/2;
if Tave(i) >= Tin * 0.1
Tave(i) = input('Enter new value of Tave:');
Tin = Tave(i);
G(i + 1) = Tin;
else
display(Tave(i))
end
end
This way its continue to ask me a new value for Tave and I dont have idea of wich value is good to input
maybe it will be better if you view value and then next value which can make Tave less then 10% of Tin.
Tave(i)=(Tw+Tb)/2;
if Tave(i) >= Tin * 0.1
display(Tave(i));
Tave(i) = input('Enter new value of Tave:');
Tin = Tave(i);
G(i + 1) = Tin;
else
display(Tave(i))
end
Try this way. Also I have no idea which values you should input for this purpose hahaha. So this idea you should think by yourself
I'm sorry the newbie ask, but in this programa the value of Tw is being changing every time that Tave changes, isn't it?
Yes value of Tw is changing in each for loop iteration and so Tave also changes each time

Iniciar sesión para comentar.

Más respuestas (2)

need_to_continue = true;
while need_to_continue
Tin = input('Temperature In');
....
need_to_continue = (Tw + Tb)/2 > Tb/10; %average is more than 10% ?
end

Categorías

Más información sobre Simscape Multibody en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 9 de Dic. de 2013

Comentada:

el 10 de Dic. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by