x=[2.32 2.37 2.06 2.16 2.04 1.89 1.90 2.14 1.89 1.69 1.97 1.751.78 1.65 1.51 1.65];�nsity
y=[6.91 6.59 3.73 3.77 5.20 2.96 3.32 5.02 5.27 2.31 5.44 3.34 7.122.82 2.38 3.51];%Young's modulus
plot(x,y,'o');%画出数据点
p=polyfit(x,y,1);%求拟合直线
xx=1.5:0.1:2.4;
yy=polyval(p,xx);
hold on; %图形保持,以在同一坐标系中画出原始数据点及拟合直线
plot(xx,yy,'r');
%下面求解决定系数
mean_y=sum(y)/length(y);
SS_T=sum(y.^2)-(sum(y))^2/length(y);
SS_R=0;
for i=1:length(y)
SS_R=SS_R+(polyval(p,x(i))-mean_y)^2;
end
R=SS_R/SS_T;