Given the data set with t values in the first column and y values in the second column, write a script file that:
-Curve fits the given data set with an appropriate polynomial function
-Outputs the R2 value of the appropriate fit along with the values of the polynomial order higher and lower (ex. If you choose a 2nd order fit, display the R2 value for first, second, and third order fits.)
- Estimate the value of the data at t = 15.5 using a 3 point interpolation.
Copy and paste the below values in excel and use that to pull data into your Matlab script file.
If you need any additional information then comment, thanks!
0 |
3 |
0.5 |
1.68569428820791 |
1 |
-3.95784854932628 |
1.5 |
-2.70275004645052 |
2 |
-8.20804222177874 |
2.5 |
-9.7888937947024 |
3 |
-10.8794243196858 |
3.5 |
-16.6350020109363 |
4 |
-15.3341094985447 |
4.5 |
-20.575599024921 |
5 |
-22.2647035001955 |
5.5 |
-22.9502699366898 |
6 |
-28.6160632481857 |
6.5 |
-27.0985091529083 |
7 |
-31.8763653389923 |
7.5 |
-33.4893475992729 |
8 |
-33.5897736790413 |
8.5 |
-38.9634230062392 |
9 |
-37.0581929509318 |
9.5 |
-41.1733606982684 |
10 |
-42.5247497074079 |
10.5 |
-41.8608395460318 |
11 |
-46.7395103467172 |
11.5 |
-44.2753705569831 |
12 |
-47.5296212422044 |
12.5 |
-48.4328411108291 |
13 |
-46.8263426410198 |
13.5 |
-51.0067929600693 |
14 |
-47.8122186368842 |
14.5 |
-50.0081973545762 |
15 |
-50.2755632708189 |
15.5 |
-47.5491275196853 |
16 |
-50.8277773078467 |
16.5 |
-46.7308822816937 |
17 |
-47.6721512398972 |
17.5 |
-47.1148702832052 |
18 |
-43.0920066727989 |
18.5 |
-45.2650085942502 |
19 |
-40.0934765705277 |
19.5 |
-39.5845544477838 |
clear
clc
A=xlsread('Exam2_Data.xlsx');
t=A(:,1);
y=A(:,2);
SST=sum((y-mean(y)).^2);
for i=1:3
fprintf('For %d order fit\n\n',i);
disp('Polynomial coefficients are');
C=polyfit(t,y,i)
SSR=sum((y-polyval(C,t)).^2);
R2=1-SSR/SST;
fprintf('R^2 is %f\n\n',R2);
end
for i=2:length(t)-1
T=[t(i-1) t(i) t(i+1)];
Y=[y(i-1) y(i) y(i+1)];
if(t(i)<15.5&t(i+1)>15.5)
C=polyfit(T,Y,2);
disp('Value at 15.5 is ');
polyval(C,15.5)
return
end
end
Kindly revert for any queries
Thanks.
Get Answers For Free
Most questions answered within 1 hours.