Help with function with nested ifs
조회 수: 1 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (1개)
KALYAN ACHARJYA
2019년 9월 22일
편집: KALYAN ACHARJYA
2019년 9월 22일
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
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!