MatLab Script Exercise

Watch this thread
username1112782
Badges: 2
Rep:
? You'll earn badges for being active around the site. Rep gems come when your posts are rated by other community members.
#1
Report Thread starter 6 years ago
#1
Please could somebody help me with this MatLab script-writing exercise? I'm very confused and don't know where to start. I'm not sure what it's asking. I have been given this background information and these instructions:
1. The least-squares method involves the minimisation of the root-mean-squared (r.m.s.) value Image of the differences between real data points Image and fitted data values Image:ImageAs we are only interested in minimising this formula and not in the value of Image, we can drop the the Image to obtain:ImageFor a straight-line fit of Image, we can write this as:ImageIf we take derivatives of Image with respect to Image and Image, we obtain the equations:ImageandImageWrite a function that calculates the summations, solves for Image and Image for input arrays x and y and returns Image, Image and the r.m.s. value for the data set. You should then write a script that calls this function and prints both a list of Image,Image, and Image values and the values of Image, Image and Image. Your script should also plot Image and Image against Image.2. Having fitted linear data using the least-squares method, it is now time to try fitting higher-order polynomials.First, you should write a function for generating data. Your data will be obtained from a polynomial with coefficients Image to Image with an added Gaussian error term Image:ImageHere, Image is the experimental r.m.s. value we wish our data to have, and Image is a Gaussian random number with mean 0 and variance 1. This can be done by generating a pair of random numbers Image and Image between 0 and 1 using the rand() function. You can then obtain a Guassian random number Image via:ImageThe MATLAB built-in function randn() is equivalent to this and returns an array of normally-distributed numbers with mean 0 and standard deviation 1. MATLAB also has a function normrnd() in its Statistics Toolbox which takes the mean and standard deviation as arguments along with the size of the resulting output. As usual, the help normrnd and help randn commands document all the details of how to use these two functions.Note that a linear fit is the special case where the polynomial is of order 1.Next, you should try curve fitting polynomials. In this case, for a polynomial of order Image you end up with Image equations and unknowns:Imagewhere Image is the index of the equation and:ImageThe equation:Imagemay be solved in two ways. The first (and mathematically intuitive) way is to multiply by the inverse of Image:Imageor in MATLAB:c = inv(A) * v;This works, but is rather slow and has issues with numerical precision. A better way is to perform Gaussian row reduction to obtain the reduced-row-echelon form of the matrix. This process is described in detail in the vectors and matrices course.MATLAB has two options for Gaussian elimination. The first is to use the rref() function, which returns the row-reduced echelon form of an Image matrix:row_reduced_form = rref([A, v]).
0
reply
X

Quick Reply

Attached files
Write a reply...
Reply
new posts
Back
to top
Latest
My Feed

See more of what you like on
The Student Room

You can personalise what you see on TSR. Tell us a little about yourself to get started.

Personalise

Has advance information helped during your exams?

Yes (130)
66.33%
No (44)
22.45%
I didn't use it to prepare (22)
11.22%

Watched Threads

View All