Question: How to write this matlab function? In many situations, functions can be approximated as sums of sine and cosine functions. in this question, you will
In many situations, functions can be approximated as sums of sine and cosine functions. in this question, you will approximate functions as sums of sine and cosine functions using least-squares linear regression. Given x- and y-data, you will fit a function of the form: f (x) = k + sigma^n_i = 1 a_i sin (ix) + sigma^n_i = 1 b_i cos (ix) where n is an integer that is greater than zero, and where tin* coefficients to fit are k, a_i, i = {1, 2, ellipsis, n}, and b_i, i = {1, 2, ellipsis, n}. Write a function with the following header: function [k, a, b] = my regression_sincos(x_data, y_data, n) where: x data and y data are two m times 1 arrays of class double that represent two-dimensional data. in other words, those column vectors represent a set of points of coordinates (x data (i), y_data (i)), i = {1, 2, ellipsis, m}. You can assume that, m > 1, and that all elements of x data and y data are different from NaN. Inf. and -Inf. n is a scalar of class double that represents n in liquation 1. You can assume that n is an integer such that n > theta. k is a scalar of class double that represents k in Equation 4. a and b are n times 1 arrays of class double such that a (i) represents a_i in Equation 1 and b (i) represents b_i in Equation 4. k, a, and b represent the coefficients of Equation 4, fitted to the x- and y-data represented by x data and y_data (respectively), using least-squares linear regression
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
