Need help with creating a function of three parameters

1 Ansicht (letzte 30 Tage)
Stirling Ellis
Stirling Ellis am 2 Mai 2022
Kommentiert: Jon am 2 Mai 2022
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 Kommentare
Torsten
Torsten am 2 Mai 2022
The problem is part of the answer. So it doesn't help to delete it here.
Stirling Ellis
Stirling Ellis am 2 Mai 2022
Didn't think it through. Went ahead and re uploaded it. Thank you

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Jon
Jon am 2 Mai 2022
Bearbeitet: Jon am 2 Mai 2022
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

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by