Help with function with nested ifs

조회 수: 1 (최근 30일)
Kevin Le
Kevin Le 2019년 9월 22일
편집: KALYAN ACHARJYA 2019년 9월 22일
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

답변 (1개)

KALYAN ACHARJYA
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

카테고리

Help CenterFile Exchange에서 Modeling에 대해 자세히 알아보기

태그

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by