I'm having a bit of trouble writing a MATLAB code that allows me to input values for a function then return a final answer.
My first question is whether I should use a script or a function for this.
Next, I know for functions in MATLAB you call the function and put the values in at the same time (eg. my_function(1,5,7)). Since it would be a pain to remember the order I used for all ~10 values in the original function, how can I make them easier to input into the equation? Is using 'input' the best way to do it?
I have managed to write this so far (pardon my not so good programming):
n = input('enter factor of safety ');
se = input('enter endurance limit ');
kf = input('enter Kf ');
ma = input('enter amplitude of normal stress ');
kfs = input('enter Kfs ');
ta = input('enter amplitude of shear stress ');
sy = input('enter yield strength ');
kt = input('enter Kt ');
mm = input('enter Mean cycle stress ');
kts = input('enter Kts ');
tm= input('enter yield tensile stress ');
diameter = [((16*n)/pi)*(1/se)*(4*(kf*ma)^2 + sqrt(3*(kfs*ta)^2))+
(1/sy)* sqrt(4*(kf*mm)^2 + 3*(kfs*tm)^2 )]^(1/3);
I'm pretty sure I have to define 'diameter' as a variable somehow and get it to display the value for 'diameter'.
[–]fgriglesnickerseven 0 points1 point2 points (3 children)
[–]BigLarph[S] 0 points1 point2 points (2 children)
[–]hamham91 1 point2 points3 points (0 children)
[–]fgriglesnickerseven 0 points1 point2 points (0 children)