Need help with creating a function of three parameters
1 次查看(过去 30 天)
显示 更早的评论
Need help creating a function of three parameters. Below I have my code, but it returns no values. The code should take in the parameters H, VR, and TR. Here is the snip below:
l = 300; %m
wo = 1e5; %Nm
f = 20; %
H = wo * l.^2 ./ (8*f); %Horizontal reaction force
VR = wo .* l / 2; %Vertical reaction force
TR = VR * sqrt(1+ l.^2 ./ (16 * f.^2)); %Tension in cable
L = 1/2 * sqrt(1+ (wo .* l / (2*H)) .^2 ) + H/wo * sinh(wo * l/ (2*H));
%MATLAB function to take in three parameters
function [output] = Force(l,wo,f)
end
Thank you in advance!
2 个评论
采纳的回答
Jon
2022-5-2
编辑:Jon
2022-5-2
You're close. Just put the formulaes inside of the function, and return the outputs of interest. Something like the code shown below. (It looks like you also wanted to compute L, the tension in the cable so I included that in the function. You could also just have returen H, VR,and TR in the function and then computed L.)
Also, to keep everything just in the one screen in the post I put the function at the bottom of a script. You could also save it as a separate .m file
% Inputs:
% l = bridge length (m)
% wo = load per unit length (N/m) % f = cable sag distance (m)
% Outputs:
% H = horizontal force at cable support point (N)
% VR = vertical reaction force at cable support point (N) % TR = cable tension force at support point (N)
l = 400; %m
wo = 1.5e5; %Nm
f = 20; %m
% call the function
[H,VR,TR,L] = Force(l,wo,f)
%MATLAB function to take in three parameters
function [H,VR,TR,L] = Force(l,wo,f)
% Formulas
H = wo * l.^2 ./ (8*f);
VR = wo .* l / 2;
TR = VR * sqrt(1+ l.^2 ./ (16 * f.^2));
% tension in cable
L = 1/2 * sqrt(1+ (wo .* l / (2*H)) .^2 ) + H/wo * sinh(wo * l/ (2*H));
end
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!