MATLAB: Polyval function not working in the fatigue failure analysis problem

fatigue-failure analysispolyfitpolyval

This is a fatigue failure analysis of a shaft with an unknown diameter.
The issue being we have a lack of information.
So, we assume a diameter and perform multiple iterations to find the correct factor of safety. The factor of safety is given.
u = symunit;
%Given information at the beginning of problem
Sy = 420e6*u.Pa; %Yield strength
Sut = 560e6*u.Pa; %Ultimate strength
TA = 340*u.N*u.m; %Given applied torque
d = .15*u.m ;
theta = 20;
BC = .25*u.m;
CD = .1*u.m;
n = 2.5;
F = vpa(TA/(cosd(theta)*d/2),5); %Acting force.
%Sum of forces and Sum of moments to find the critical point of interest and the max bending moment.
C_z = vpa(F*sind(theta)*(BC+CD)/BC,4);
B_z = vpa(F*sind(theta)-C_z ,4);
M_z = abs(B_z*BC );
C_y = vpa(F*cosd(theta)*(BC+CD)/BC,4);
B_y = vpa(F*cosd(theta)-C_y ,4);
M_y = abs(B_y*BC);
M_max = vpa(sqrt(M_y^2 + M_z^2),4)
%Torque on the whole system.
T = F*cosd(theta)*d/2 + TA;
Se_p = .5*Sut;
a = 3.04;
b = -0.217;
%kb, ka, kc constants help determine endurance strength
ka = a*separateUnits(Sut)^(b);
Instead of doing multiplie iterations I just created a range of diameter values where it satisfied a factor of safety.
d = linspace(.04,.15)*u.m; %Here's my range of diametric values.
kb = 1.24.*separateUnits(d).^(-.107);
kc = 1;
Se = Se_p.*ka.*kb.*kc;
% sharp fillet concentration factors
kt = 2.7;
kts = 2.2;
%inertia and polar moment of inertia.
I = pi.*d.^4./64;
J = pi.*d.^4./32;
%Alternating bending stress
sigma_alt = kt.*M_max.*32./(pi.*d.^3);
%Mean bending stress
sigma_m = 0;
% Alternating torsion stress
tao_alt = 0;
%mean torsion stress
tao_m = kts.*16.*T./(pi.*d.^3);
%Von mises alternating stress
sigma_altp = (sigma_alt.^2 + 3*tao_alt.^2).^(1/2);
%Von mises mean stress
sigma_mp = (sigma_m^2 + 3.*tao_m.^2).^(1/2);
A = sqrt(4*(kt*M_max)^2+3*(kts*0).^2);
B = sqrt(4*(kt*0)^2+3*(kts*T).^2);
%Goodman criteria for solving factor of safety
n = simplify(pi.*d.^3./16.*(A./Se + B./Sut).^(-1))
Now that I have a range of values for the factor of safety, I can use polyfit function to find the coefficients to solve for an exact diameter.
When I apply the polyfit function it gives me coefficients.
x1 = polyfit(separateUnits(d),n,2)
When I apply the polyval so that I can get the precise diameter value, it gives me an error.
polyval(x1,2.5)
Specifically:
Error using filter
Invalid data type. Input
arrays must be numeric
or logical.
Error in polyval (line
56)
y = filter(1,[1
-x],p);
Error in Untitled (line
83)
polyval(x1,2.5)
Why doesn't this work? Thank you.

Best Answer

If you are calling polyfit as:
x1 = polyfit(separateUnits(d),n,2)
you need to call polyval as:
v = polyval(x1,separateUnits(d))
since ‘separateUnits(d)’ appears to be your independent variable.
(I do not see that anywhere in your posted code, though.)
Related Question