Help with function with nested ifs
Afficher commentaires plus anciens
It produces errors past 120 cols, but works perfectly fine for a matrix of 1x120.
function [v] = Deflection_klle(x) %Deflection_klle will calculate the deflection of a defined beam % v=Deflection % x=Position
if (x>=0 & x<=120) v=(1/(3.19*10^9)).*((800.*(x.^3))-(13.68.*(10^6).*x)-(2.5.*(x.^4)));
elseif (x>120 & x<=240) v=(1/(3.19*10^9)).*((800.*(x.^3))-(13.68.*(10^6).*x)-(2.5.*(x.^4))+(2.5.*((x-120).^4)));
elseif (x>240 & x<=360) v=(1/(3.19*10^9)).*((800.*(x.^3))-(13.68.*(10^6).*x)-(2.5.*(x.^4))+(2.5.*((x-120).^4))+(600*((x-240).^3))); else end
end
Réponses (1)
KALYAN ACHARJYA
le 22 Sep 2019
Modifié(e) : KALYAN ACHARJYA
le 22 Sep 2019
function [v]=Deflection_klle(x)
%Deflection_klle will calculate the deflection of a defined beam
% v=Deflection
% x=Position
if (x>=0 && x<=120)
v=(1/(3.19*10^9)).*((800.*(x.^3))-(13.68.*(10^6).*x)-(2.5.*(x.^4)));
elseif (x>120 && x<=240)
v=(1/(3.19*10^9)).*((800.*(x.^3))-(13.68.*(10^6).*x)-(2.5.*(x.^4))+(2.5.*((x-120).^4)));
elseif (x>240 && x<=360)
v=(1/(3.19*10^9)).*((800.*(x.^3))-(13.68.*(10^6).*x)-(2.5.*(x.^4))+(2.5.*((x-120).^4))+(600*((x-240).^3))); else end
end
Command Window: I have tested with random x data
>> Deflection_klle(5)
ans =
-0.0214
Catégories
En savoir plus sur Testing Frameworks dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!