Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

What I have so far... clear; x = [1 2 3 4 6 7]; y = [2 4 7 1 3 5]; n =3; m

image text in transcribed

What I have so far...

clear;

x = [1 2 3 4 6 7]; y = [2 4 7 1 3 5]; n =3; m =length(x); A =zeros(n,n); a =zeros(n,1); %coefficient matrix b =zeros(n,1); %solution matrix (Aa=b)

A (1,:) = [m,sum(x),sum(x.^2)]; %force first row %loop for rows 2 through n for i=2:n A(i,:) = [sum(x.^(i-1)),sum(x.^(i)),sum(x.^(i+1))]; end %loop for the b matrix for i=1:n b(i) = sum(y.*(x.^(i-1))); end a= A\b; %solve for a

scatter(x,y,'k*');

To hand in your Matlab work, please email your files to me. 1) Write Matlab code to implement the discrete least squares method of finding the best-fit polynomial of degree n for a set of m data points. The pertinent information should be read from a data file called lsdata.m For example, if we want to use a cubic (degree 3) polynomial and 6 data points, then 1sdata.m should contain 1 2 2 4 7 5 where the first two entries are respectively n and m and the remaining rows contain the coordinates of the 6 data points Your program should produce a picture of the least squares polynomial and the data points. You may not use the Matlab command polyfit. Also, what is the relationship between n and m that must exist for the least squares problem to make sense? If the relationship does not hold, deal with this appropriately

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Seven NoSQL Databases In A Week Get Up And Running With The Fundamentals And Functionalities Of Seven Of The Most Popular NoSQL Databases

Authors: Aaron Ploetz ,Devram Kandhare ,Sudarshan Kadambi ,Xun Wu

1st Edition

1787288862, 978-1787288867

More Books

Students also viewed these Databases questions