Question

Consider the following table of data points:

f(x) i Xi 0 0.000 1.00000 1 0.125 0.98450 2 0.250 0.93941 0.375 0.86882 4 0.500 0.77880 5 0.625 0.67663 6 0.750 0.56978 0.875

Using least squares fitting, find the polynomial Q(x) of degree 2 that fits the data points given in the table above. Approximate f(0.3) using Q(0.3).

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Matlab code for 1least square fit of degree 2 polynomial clear all close all All data given 0.250 0. 375 0.500 0.625 0.750 .0hold on plot (xx, fx, r*) plot (xx, fp) xlabelx) ylabelf(x) ) title f(x) vs x plot) legendActual data,fitted data) EnOrder 2 polynomial function is Q(x)= - 0.379203 *x*2 - 0.289905 *x 1.01824 symbolic function inpu ts: x Hence f(0.3) using Q(

%%Matlab code for least square fit of degree 2 polynomial
clear all
close all

%All data given
xx=[0.000 0.125 0.250 0.375 0.500 0.625 0.750 0.875 1.000];
fx=[1.00000 0.98450 0.93941 0.86882 0.77880 0.67663 0.56978 0.46504 0.36788];

%displaying the data
fprintf(' \t\t\t\tx f(x) \n')
disp([xx' fx']);

%finding degree 2 polynomial
%creating A matrix
for i=1:length(xx)
  
    A(i,1)=1;
    A(i,2)=xx(i);
    A(i,3)=(xx(i)).^2;
  
end

%displaying A matrix
fprintf('\ndisplaying A matrix\n\n')
disp(vpa(A,6))


fprintf('\ndisplaying AT*A matrix\n\n')
disp(vpa(A'*A,6))

fprintf('\ndisplaying AT*fx matrix \n\n')
disp(vpa(A'*fx',6))

fprintf('The coefficient for degree 2 polynomials are\n')
c=(inv(A'*A))*A'*fx';
disp(c)

fprintf('Order 2 polynomial function is Q(x)= ')
syms x
Q(x)= c(1)+c(2).*x+c(3).*x.^2;
disp(vpa(Q,6))

fprintf('\tHence f(0.3) using Q(0.3) is %f\n',Q(0.3))

%plotting the data and polynomial
for j=1:length(xx)
  
    fp(j)=double(Q(xx(j)));
  
end

hold on
plot(xx,fx,'r*')
plot(xx,fp)

xlabel('x')
ylabel('f(x)')
title('f(x) vs. x plot')
legend('Actual data','fitted data')

%%%%%%%%%%%%%%%%%%%%% End of Code %%%%%%%%%%%%%%%%%%
  

Add a comment
Know the answer?
Add Answer to:
Consider the following table of data points: Using least squares fitting, find the polynomial Q(x) of degree 2 that fit...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT