Objective #1: Implement a function in Matlab that finds that parameters, b_hat, of a polynomial regression model. Begin from 'regress_fit_poly.m', which is a stub (i.e., unfinished) version of the function provided for you. The inputs and outputs of your function should conform to the following specifications: % Inputs: % x - A n-by-1 vector of feature values % (where n is number of data points) % y - A n-by-1 vector of response variable values % p - A scalar value, indicating the polynomial order % Outputs: % b_hat - a p+1-by-1 vector of regression coefficients Note: Your function should be able to calculate the polynomial regression parameters for a model of any order (i.e., an input ‘p’ of any value). Note: To see if your function is working correctly, you can check the outputs of your function against those produced by Matlab's 'polyfit' function. However, you should not call ‘polyfit’ inside your own function. Note: Pay special attention to the order of the parameters, which is important, and which may be different than you expect. If you notice that the parameters coming from your function differ from those of 'polyfit', think hard about how you might rearrange them to match. You have several options. For instance, you could change the ordering of columns in the design matrix. Alternatively, you could look into the Matlab functions 'fliplr' and 'flipud', which might help.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter7: Arrays
Section: Chapter Questions
Problem 12PP: (Data processing) The answers to a true-false test are as follows: T T F F T. Given a twodimensional...
icon
Related questions
Question

Objective #1:
Implement a function in Matlab that finds that parameters, b_hat, of a polynomial regression model.
Begin from 'regress_fit_poly.m', which is a stub (i.e., unfinished) version of the function provided for
you. The inputs and outputs of your function should conform to the following specifications:


% Inputs:
% x - A n-by-1 vector of feature values
% (where n is number of data points)
% y - A n-by-1 vector of response variable values
% p - A scalar value, indicating the polynomial order

% Outputs:
% b_hat - a p+1-by-1 vector of regression coefficients


Note: Your function should be able to calculate the polynomial regression parameters for a model of any
order (i.e., an input ‘p’ of any value).


Note: To see if your function is working correctly, you can check the outputs of your function against
those produced by Matlab's 'polyfit' function. However, you should not call ‘polyfit’ inside your own
function.


Note: Pay special attention to the order of the parameters, which is important, and which may be different
than you expect. If you notice that the parameters coming from your function differ from those of 'polyfit',
think hard about how you might rearrange them to match. You have several options. For instance, you
could change the ordering of columns in the design matrix. Alternatively, you could look into the Matlab
functions 'fliplr' and 'flipud', which might help.

 
### Polynomial Regression Function Documentation

#### Function Definition
```matlab
function b_hat = regress_fit_poly(x, y, p)
```

#### Purpose
The `regress_fit_poly` function computes the coefficients of a polynomial regression model given input vectors `x` and `y`, and the polynomial order `p`.

#### Inputs
- **x**: A n-by-1 vector containing feature values, where `n` denotes the number of data points.
- **y**: A n-by-1 vector containing response variable values.
- **p**: A scalar indicating the order of the polynomial.

#### Outputs
- **b_hat**: A (p+1)-by-1 vector of regression coefficients.

#### Metadata
- **Created by**: Adam C. Lammert (2020)
- **Author**: ??? (Insert your name)

#### Description
This function, `regress_fit_poly`, is designed to calculate the coefficients necessary for fitting a polynomial regression model to the provided data. The calculation is based on the feature values (`x`), the corresponding response values (`y`), and the specified polynomial order (`p`).

```matlab
% Example code snippet
% <your code goes here – several lines will be required>

return
%end of file
```

In the above script, you need to replace the placeholder `your code goes here – several lines will be required` with the actual implementation of the polynomial regression fitting.

### Note
Ensure to write efficient and clean code for the polynomial fitting and document your approach well in the script.
Transcribed Image Text:### Polynomial Regression Function Documentation #### Function Definition ```matlab function b_hat = regress_fit_poly(x, y, p) ``` #### Purpose The `regress_fit_poly` function computes the coefficients of a polynomial regression model given input vectors `x` and `y`, and the polynomial order `p`. #### Inputs - **x**: A n-by-1 vector containing feature values, where `n` denotes the number of data points. - **y**: A n-by-1 vector containing response variable values. - **p**: A scalar indicating the order of the polynomial. #### Outputs - **b_hat**: A (p+1)-by-1 vector of regression coefficients. #### Metadata - **Created by**: Adam C. Lammert (2020) - **Author**: ??? (Insert your name) #### Description This function, `regress_fit_poly`, is designed to calculate the coefficients necessary for fitting a polynomial regression model to the provided data. The calculation is based on the feature values (`x`), the corresponding response values (`y`), and the specified polynomial order (`p`). ```matlab % Example code snippet % <your code goes here – several lines will be required> return %end of file ``` In the above script, you need to replace the placeholder `your code goes here – several lines will be required` with the actual implementation of the polynomial regression fitting. ### Note Ensure to write efficient and clean code for the polynomial fitting and document your approach well in the script.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Temporal Difference Learning
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr