Question

Least Squares with polynomial functions Generate some data for x in the range of 0 to...

  1. Least Squares with polynomial functions

Generate some data for x in the range of 0 to 2 using the following function:

y = x^5 – 3*x^3 -5x + 7 + 0.5*rand(x, ‘normal’);

Create polyfit and polyeval functions to come up with coefficients for the generated data.

Please write your answer very clearly.

Homework Answers

Answer #1

MATLAB Code:

close all
clear
clc

% Data points
x = linspace(0, 2, 10); % 10 samples from 0 to 2
y = x.^5 - 3*x.^3 -5*x + 7 + 0.5*rand();

% Curve fitting
p = polyfit(x, y, 5); % Fitting 5-th degree polynomial to the data points
fprintf('Model: y = (%.4f)*x^5 + (%.4f)*x^4 + (%.4f)*x^3 + (%.4f)*x^2 + (%.4f)*x + (%.4f)\n', p)

x5 = linspace(0, 2); % Bunch of new samples for a smoother plot
y5 = polyval(p, x5);
plot(x, y, 'o'), hold on % Plot the data points
plot(x5, y5), hold off % Plot the fitted curve
xlabel('x'), ylabel('y')
legend('Data Points', 'Fitted Curve')

Output:

Model: y = (1.0000)*x^5 + (0.0000)*x^4 + (-3.0000)*x^3 + (0.0000)*x^2 + (-5.0000)*x + (7.2844)

Plot:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Generate some data for x in the range of 0 to 2 using the following function:...
Generate some data for x in the range of 0 to 2 using the following function: y = x^5 – 3*x^3 -5x + 7 + 0.5*rand(x, ‘normal’); Create polyfit and polyeval functions to come up with coefficients for the generated data. Please write your answer very clearly.
1) Given the following information, what is the least squares estimate of the y-intercept? x y...
1) Given the following information, what is the least squares estimate of the y-intercept? x y 2 50 5 70 4 75 3 80 6 94 a)3.8 b)5 c) 7.8 d) 42.6 2) A least squares regression line a) can only be determined if a good linear relationship exists between x and y. b) ensures that the predictions of y outside the range of the values of x are valid. c) implies a cause-and-effect relationship between x and y. d)...
This is C++ programming. Use separate compilation to implement a polynomial ADT that manipulates polynomials in...
This is C++ programming. Use separate compilation to implement a polynomial ADT that manipulates polynomials in a single variable x (e.g., p = 4 x^5 + 7 x^3 – x^2 + 9 ). For this problem, consider only polynomials whose exponents are non-negative integers. You are required to identify a proper data representation schema to store such polynomials and hide such data from external users of this ADT. Additionally, your ADT will at least include the following member functions: One...
We use the form y hat = a + bx for the least-squares line. In some...
We use the form y hat = a + bx for the least-squares line. In some computer printouts, the least-squares equation is not given directly. Instead, the value of the constant a is given, and the coefficient b of the explanatory or predictor variable is displayed. Sometimes a is referred to as the constant, and sometimes as the intercept. Data from Climatology Report No. 77-3 of the Department of Atmospheric Science, Colorado State University, showed the following relationship between elevation...
Using R and install.packages("MASS"), library(MASS) 1. Generate the following vector using at least two methods. 0,...
Using R and install.packages("MASS"), library(MASS) 1. Generate the following vector using at least two methods. 0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4 2. Generate the following vector. Apple1, Banana2, Orange3, Cranberry4, Watermelon5 3. Generate the following vector using the “rep” function. a, a, b, b, c, c, a, a, b, b, c, c 4. In vector y = (8, 3, 5, 7, 6, 6, 8, 9, 2, 3, 9, 4, 10, 4, 11), which elements of y contains...
Some types of algae have the potential to cause damage to river ecosystems. The accompanying data...
Some types of algae have the potential to cause damage to river ecosystems. The accompanying data on algae colony density (y) and rock surface area (x) for nine rivers is a subset of data that come from a study. x 49 55 50 79 44 37 70 45 50 y 154 48 24 35 36 171 13 185 27 a) Find the equation of the least squares line. (Round your answers to three decimal places.) ŷ = __+__x (b)What is...
Given the data 28.65 26.55 26.65 27.65 27.35 28.35 26.85 28.65 29.65 27.85 27.05 28.25 28.85...
Given the data 28.65 26.55 26.65 27.65 27.35 28.35 26.85 28.65 29.65 27.85 27.05 28.25 28.85 26.75 27.65 28.45 28.65 28.45 31.65 26.35 27.75 29.25 27.65 28.65 27.65 28.55 27.65 27.25 Determine (a) the mean, (b) the standard deviation, (c) the variance, (d) the coefficient of variation, and (e) the 90% confidence interval for the mean. (f) Construct a histogram. Use a range from 26 to 32 with increments of 0.5. (g) Assuming that the distribution Thus, the improved estimates...
1. The data below show the historical relationship between production levels and overhead costs at your...
1. The data below show the historical relationship between production levels and overhead costs at your company. a) Construct a scatterplot of y versus x. b) Find the least-squares regression line (i.e., calculate the coefficients and show the equation) relating overhead costs to production. c) Graph the regression line on the plot. It is recommended that you use Excel to create the scatterplot, but do not use the Excel functions to calculate the slope and intercept of the regression line....
Creating and interpreting a Normal Quantile-Quantile (Normal Q-Q) plot. The data you will be using is...
Creating and interpreting a Normal Quantile-Quantile (Normal Q-Q) plot. The data you will be using is the distance in miles from home to campus for statistics students. 150      30        105      88        94        15        55        122      45        67        18        126      30 143      98        15        30        62        111      87        38        20        34        39        46        14 144      23        94        44        97        65        120      123      99        45        57        209      20 133      72 Column 1: Sort the data values from least to greatest. Use the...
For this lab assignment you will need to write some code and create some graphs. You...
For this lab assignment you will need to write some code and create some graphs. You may use excel to create your graphs, or other language of your choice. Your data needs to demonstrate the experimental running time for Selection Sort (code in book), Merge Sort (code in book), and the Arrays.sort() method. Here is a basic outline of how you need to code this assignment. 1) Create several arrays of size 100, 1000, 10000, 100000, 1000000, … (you need...