Help with function with nested ifs
Ältere Kommentare anzeigen
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
Antworten (1)
KALYAN ACHARJYA
am 22 Sep. 2019
Bearbeitet: KALYAN ACHARJYA
am 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
Kategorien
Mehr zu Testing Frameworks finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!