Write a MATLAB program to find the tensile strength sigmat a
Solution
MATLAB CODE:
clear all
clc
%Data
t=[10 15 20 25 40 50 55 60 75];
s=[5 20 18 40 33 54 70 60 78];
ti=30;
%Linear least-squares regression
R=Regress(t,s,ti);
%Newton\'s interpolating polynomial
N=NewtInt(t,s,ti);
%Lagrange interpolation
%L=Lagrng(t,s,ti); %%%%%%%%%%%%%%% THIS ISN\'T PROGRAMED YET, CONSULT THE
%%%%%%%%%%%%%%% REFERENCED TEXTBOOK BY THE PROBLEM
%MATLAB command \"polyfit\"
P=polyfit(t,s,1);
si=P(1)*ti+P(2);
M=[P si]
function R=Regress(x,y,xi)
n=length(x);
for i=1:n
xy(i)=x(i)*y(i);
x2(i)=x(i)^2;
y2(i)=y(i)^2;
end
Sx=sum(x);
Sy=sum(y);
Sxy=sum(xy);
Sx2=sum(x2);
Sy2=sum(y2);
a1=(n*Sxy-Sx*Sy)/(n*Sx2-Sx^2);
Px=Sx/n;
Py=Sy/n;
ao=Py-a1*Px;
for i=1:n
S(i)=(y(i)-(a1*x(i)+ao))^2;
end
Sr=sum(S);
R2=0;%%%%%%%%%%%%%%% FIND THE EQUATION FOR SQUARE R AN PROGRAM IT HERE
si=a1*xi+ao;
R=[a1 ao Sr R2 si]
end
function N=NewtInt(x,y,xi)
n=length(y);
k=1;
a(1)=y(1);
Y=y;
while n~=1
for i=1:n-1
f(i)=(y(i+1)-y(i))/(x(i+k)-x(i));
end
y=f;
n=n-1;
k=k+1;
N=1;
a(k)=y(1);
%%%%%%%%%%% THE COMPONENTS OF \"a\" ARE THE COEFFICIENTS a0, a1,...,an
%%%%%%%%%%% NOW USE THIS COEFFICIENTES TO WRITE THE EQUATION AND
%%%%%%%%%%% REPLACE x=xi TO KNOW si
end


