Note: You may use external means (e.g. Mathematica, wolframalpha, etc.) to calculate derivatives and perform other algebraic manipulations.
Problem 1
Using the least square method, we can find the unknown coefficients for a general equation in the form of with yis are linearly independent functions.
a) Use the least squares method to find the coefficients a0, a1, and a2 for the best-fit equation (z = a2x2 +a1 sin(x)+a0) to the data provided in HW2Problem1.csv. Column 1 has x values and column 2 has z values. Plot the data and the curve fit.
b) Now consider y1 = sin(x) and y2 = x2. A surface can be made using the same coefficients as before: z = a2y2 + a1y1 + a0. Plot this surface as well as the points ((y1)i,(y2)i,zi) on the same graph.
c) Compute maximum, average and RMS error for this fitted curve.
Provide the code used to solve this problem. Do not use built-in functions for curve-fitting.
Problem 2
There are many non-polynomial curves one may want to fit to a data set. Consider a case where you would like to fit an exponential function of the form y = Aexp(Bx) to your data.
a) Manipulate the above exponential function to obtain a linear function: y˜ = Cx + D. What is the relationship between y˜ and y? What are the values of C and D in terms of A and B?
b) With the insight from the work completed in (a), it should be noted that a least-squares linear curvefit procedure can be used to determine the coefficients in an exponential curve fit. Import the data from HW2Problem2.csv, x values are in column 1 and the y values in column 2, and find the coefficients A and B for an exponential curve fit of the form y = Aexp(Bx − 2). Plot the data and the exponential fit.
Provide the code used to solve this problem. You should not use any built-in functions related to curvefitting.