Help with function with nested ifs
显示 更早的评论
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
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
类别
在 帮助中心 和 File Exchange 中查找有关 Testing Frameworks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!