Need help with creating a function of three parameters

1 visualizzazione (ultimi 30 giorni)
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 Commenti
Torsten
Torsten il 2 Mag 2022
The problem is part of the answer. So it doesn't help to delete it here.
Stirling Ellis
Stirling Ellis il 2 Mag 2022
Didn't think it through. Went ahead and re uploaded it. Thank you

Accedi per commentare.

Risposta accettata

Jon
Jon il 2 Mag 2022
Modificato: Jon il 2 Mag 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

Più risposte (0)

Categorie

Scopri di più su Programming in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by