In: Math
Answer all the question below.
Table 2:
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 |
12.2373551424579 11.7708440253038 11.3114033194700 11.0981090241345 10.9917532871426 10.9633449623870 10.9328985186904 11.0609123182770 11.1447150124713 11.2994243413533 11.4699411879533 11.5862580969086 11.7887055678588 11.9277833926721 11.9332325617172 12.0027754228957 12.0455191817870 11.9895076044597 12.1161492247957 11.9142999902406 11.9523445384738 11.8444716643177 11.8325572681845 11.6394782554936 11.4409836766153 |
Need to solve this all question. Please Provide the proper solution. Thank you
Please upvote. If you have any doubt, please ask. I will answer as soon as possible !
%**********************************The code in matlab starts below*****************************
%**********************************PART 1 *****************************
% Storing the data before any computation
xdata = [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49];
ydata = [12.2373551424579,11.7708440253038,11.3114033194700,11.0981090241345,10.9917532871426,10.9633449623870,10.9328985186904,11.0609123182770,11.1447150124713,11.2994243413533,11.4699411879533,11.5862580969086,11.7887055678588,11.9277833926721,11.9332325617172,12.0027754228957,12.0455191817870,11.9895076044597,12.1161492247957,11.9142999902406,11.9523445384738,11.8444716643177,11.8325572681845,11.6394782554936,11.4409836766153];
% plotting the data figure
plot(xdata,ydata,'x')
hold on
% to plot a fitting curve later
%**********************************PART 2 *****************************
%Interpolating the value(linear interpolation)
y_interpolated= interp1 (xdata, ydata, [8,20]);
fprintf('At X=8, interpolated value of Y= is %.4f \n', y_interpolated(1))
fprintf('At X=20, interpolated value of Y= is %.4f \n', y_interpolated(2))
%**********************************PART 3 *****************************
% FItting the Data with polynomial function
order =4
% here 4 is the order of the polynomial which fits the data well
poly = polyfit(xdata,ydata,4);
% poly contains the coefficients of the polynomial function
%plotting the function
fprintf("The function for the fit is: ")
fprintf('%.7f*X^4 + %.7f*X^3 + %.7f*X^2 + %.7f*X + %.7f = 0',poly(5),poly(4),poly(3),poly(2),poly(1))
%Now plotting the fitted plynomial over the previous plot
x_fit = linspace(1,49,200);
% getting a vector of equally spaced points from 1 to 49
y_fit = polyval(poly,x_fit);
% it calcualtes the polynomial at the x_fit values
plot(x_fit,y_fit)
% plot the polynomial curve over the data points
hold off
%**********************************PART 4 *****************************
%Interpolating the value(from the fitted cuve)
y_interpolated= polyval (poly, [8,20])
fprintf('At X=8, interpolated value of Y(from fitted curve)= is %.4f \n', y_interpolated(1));
fprintf('At X=20, interpolated value of Y(from fitted curve)= is %.4f \n', y_interpolated(2));
%*******************************outputs are below************************************
Console output:
The graph is:
At X=8, interpolated value of Y= is 11.0449 At X=20, interpolated value of Y= is 11.3847 order - 4 The function for the fit is: 12.5695061*X4 + -0.3494972*X^3 + 0.0239355*X^2 + -0.0005554 *x + 0.0000042 = Øy_interpolated - 11.038 11.375 At X=8, interpolated value of Y(from fitted curve)= is 11.0381 At X=20, interpolated value of Y(from fitted curve), is 11.3751
12.5 12 - 11.5 x 11 10.5 0 10 20 30 40 50