Please reply to above problem even when condition is true i.e Beta value is 0.3 , then also inside statements i.e formulas of Fxc ,Fx Fxy are not executed .
Multiple elseif command not working even when condition is true
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Dhananjay Hiwase
el 29 de Abr. de 2021
Comentada: Dhananjay Hiwase
el 30 de Abr. de 2021
%% in below code for Bita =0.3 and 0.1 and 0.2 and 0.6 it is not executing inside statement however for Bita=0.4 and 0.5 only it is working please reply
Alpha = input ('Enter the value of alpha layer from 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8 = ');
x= input ('Enter the value of gamma layer from 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8 = ');
Bita=1-Alpha-x;
if Bita == 0.1
Fx =0.2065*(x^2)-1.0425*(x)+0.9486;
Fxt =Fx*2326.2; %in Mpa IM7/8552 table 1.4 barbero pg.33
Fxc =-0.1508*(x^3) + 0.1658*(x^2) - 0.8379*(x) + 0.922;
Fxc =Fxc*1200.1; %in Mpa IM7/8552 table 1.4 barbero pg.33
Fxy=0.3524*(x)+.0884;
Fxy=Fxy*1200.1; %in Mpa IM7/8552 table 1.4 barbero pg.33
elseif Bita == 0.2
Fx =-0.2797*(x^2) - .607*(x)+ 0.8112;
Fxt =Fx*2326.2; %in Mpa
Fxc =44.032*(x^6) - 103.87*(x^5) + 94.683*(x^4) - 41.999*(x^3) + 9.3574*(x^2) - 1.716*(x)+ 0.8608;
Fxc =Fxc*1200.1; %in Mpa
Fxy=0.3524*(x)+.0884;Fxy=Fxy*1200.1; %in Mpa
elseif Bita == 0.3
disp(Bita)
Fx =-.8*(x)+.74; Fxc=Fx;
Fxt = Fx*2326.2; %in Mpa
Fxc = Fxc*1200.1; %in Mpa
Fxy=.3524*(x)+.0884;Fxy=Fxy*1200.1; %in Mpa
elseif Bita == 0.4
Fx =-.6*(x-.1)+.565; Fxc=Fx;
Fxt = Fx*2326.2; %in Mpa
Fxc = Fxc*1200.1; %in Mpa
Fxy=.3524*(x)+.0884;Fxy=Fxy*1200.1; %in Mpa
elseif Bita == 0.5
Fx = -.8*(x-.1)+.475; Fxc=Fx;
Fxt = Fx*2326.2; %in Mpa
Fxc = Fxc*1200.1; %in Mpa
Fxy=.3524*(x)+.0884;Fxy=Fxy*1200.1; %in Mpa
elseif Bita == 0.6
Fx =-.8*(x-.1)+.38; Fxc=Fx;
Fxt = Fx*2326.2; %in Mpa
Fxc = Fxc*1200.1; %in Mpa
Fxy=.3524*(x)+.0884;Fxy=Fxy*1200.1; %in Mpa
elseif Bita == 0.7
Fx =-.8*(x-.1)+.284; Fxc=Fx;
Fxt = Fx*2326.2; %in Mpa
Fxc = Fxc*1200.1; %in Mpa
Fxy=.3524*(x)+.0884;Fxy=Fxy*1200.1; %in Mpa
end
Respuesta aceptada
DGM
el 29 de Abr. de 2021
Beware strict equality tests when using floating point numbers. There are a few things you could try:
You could try to clean up the result in the hopes that it matches using an equality test:
Bita=round((1-Alpha-x)*10)/10;
Or the more robust approach is probably to test against a tolerance:
tol=1E-12;
if abs(Bita-0.1)<tol
% ...
elseif abs(Bita-0.7)<tol
% ...
else
% figure out how to handle all other cases
end
And add a case to catch all other inputs
Ver también
Categorías
Más información sobre Assembly en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!