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)...
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...
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...
Although there is some truth in the following statements, which best describes accepting risk as part...
Although there is some truth in the following statements, which best describes accepting risk as part of a decision-making process, given the definition of risk we have used in this class? Taking a course of action when you are not sure about what will happen in the future. Taking a course of action even though you know that only bad things could possibly happen. Taking a course of action when you are uncertain about the future, but only good outcomes...
*Answer all questions using R-Script* Question 1 Using the built in CO2 data frame, which contains...
*Answer all questions using R-Script* Question 1 Using the built in CO2 data frame, which contains data from an experiment on the cold tolerance of Echinochloa crus-galli; find the following. a) Assign the uptake column in the dataframe to an object called "x" b) Calculate the range of x c) Calculate the 28th percentile of x d) Calculate the sample median of x e) Calculate the sample mean of x and assign it to an object called "xbar" f) Calculate...
Conducting a Simulation For example, say we want to simulate the probability of getting “heads” exactly...
Conducting a Simulation For example, say we want to simulate the probability of getting “heads” exactly 4 times in 10 flips of a fair coin. One way to generate a flip of the coin is to create a vector in R with all of the possible outcomes and then randomly select one of those outcomes. The sample function takes a vector of elements (in this case heads or tails) and chooses a random sample of size elements. coin <- c("heads","tails")...