Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

23.65.1. Least square fit to polynomial This tool is provided by a third party.

ID: 3723610 • Letter: 2

Question

23.65.1. Least square fit to polynomial This tool is provided by a third party. Theugh ycur activity may be reccrded, a pape re'rest may be needed to fill the banner 0/15 Least square fit to polynomial Write a tunction Least3quareFt3Pol that solves a linear system of equations to find a least squares nt of a third order polynomial f(x) = aul + at, aix+ao to an experimental data set given as two row arrays The function LeastSquareFn3Pol must explicitly solve a set of linear equations and cannot use polytt. There should be no restriction on the size or the prablem that can be solved. For example: >X--5.009 2.5089 >>a3,a2,a1,ae]-LeastSquareFit3Pol(x,y) 8 2.58 S.000]: y- -55s 989. 45 345]: 3.2913 -4.5143 S.4667 7.6236 Your Function Save C Reset MATLAB Documentation function [a3, a2,a1,ae1-LeastSquareFit3Pol (xdata, 2 % Least square fit to y(x)-a3x^3ta2x^2+81x+ao ydata) % Your code goes here 6 end Code to call your function C Reset x --5.0000, -2.500e. 0. 2.50. 5.0008]: y- -555. -88,9.45, 345]: 2 [a2,a2,a1,ae]-LeastSquareFit2Pol(x,y) Run Function O Type here to search

Explanation / Answer

Here is the matlab code. Save this code in file LeastSquareFit3Pol.m

/********************/

function [a3,a2,a1,a0]=LeastSquareFit3Pol(xdata,ydata)
%Least square fit to y(x)=a3x^3+a2x^2+a1x+a0
f=polyfit(xdata,ydata,3);
a3=f(1);
a2=f(2);
a1=f(3);
a0=f(4);
end

/******************/ run this function in matlab terminal

>> x=[-5 -2.5 0 2.5 5]

x =

   -5.0000   -2.5000         0    2.5000    5.0000

>> y=[-555 -88 9 45 345]

y =

-555   -88     9    45   345

>> [a3,a2,a1,a0]=LeastSquareFit3Pol(x,y)

a3 =

    3.3813


a2 =

   -4.5143


a1 =

    5.4667


a0 =

    7.6286

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote