Answered step by step
Verified Expert Solution
Question
1 Approved Answer
LAB ACTIVITY 8 . 5 . 1 : MATLAB: Least Squares Approximation This tool is provided by a third party. Though your activity may be
LAB ACTIVITY : MATLAB: Least Squares Approximation This tool is provided by a third party. Though your activity may be recorded, a page refresh may be needed to fill the banner. MATLAB: Least Squares Approximation In this activity you will use a least squares approximation to find a curve of best fit for a data set. Consider the four points in the plane: and Use the least squares approximation to find the bestfit line for this data. Note Y is the vector b in the inconsistent system AxbEnter the data as two column vectors. X Y Use the length command to determine the size of the column vector. m lengthXSet up the appropriate matrix A to find the bestfit line of the form yCDx The first column Sof A will contain all ls This is achieved here using the ones command to create a column vector of length m of all is The second column of A contains X A ones m XCalculate the matrix products. AtransposeA A A AtransposeY A YUse the backslash operation to solve the overdetermined system. Soln AtransposeAAtransposeY The points will range from to in increments of Generate points to plot the bestfit line. X: : ylinear Soln SolnX The following sequence of commands plots the data and the line of best fit. plotx ylinear, X Yk;grid;shg The MATLAB code produces the following image. A line may not be the best fit for this data. For this activity, use the same data and find the bestfit parabola.Script e Save C Reset MATLAB Documentation These are provided for you. The same data is used for the activity. X Y Use the length command to determine the size of the column vector X Store this value in m m lengthXSet up the appropriate matrix A to find the bestfit parabola of the form yCDxEx The first column of A will contain all ls using the ones command. The second column of A contains x values that are stored in X The third column of A contains the squared x values that are stored in X Elementwise multiplication of x by itself, using operator, will produce the desired values for the third column. A ones m XCalculate the matrix products. These are provided for you. AtransposeA A A Atranspose Y A Y Use the backslash operation to solve the overdetermined system. Store this in Soln Soln AtransposeAAtransposeY Define the x values to use for plotting the bestfit parabola. This creates a vector xThis is provided for you. x: : Define the bestfit parabola, storing it in yquadratic. Elementwise multiplication of the x values times themselves to square them is achieved by using operator because x is a vector yquadratic Soln Solnx The following sequence of commands plots the data and the bestfit parabola. The command is provided for you. plotx yquadratic, X Yk;grid;shg
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started