Question

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.

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.2839)

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
Least Squares with polynomial functions Generate some data for x in the range of 0 to...
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.
f (x, y) =(x+y)/(5(5 + 2)) is a joint probability density function over the range 0...
f (x, y) =(x+y)/(5(5 + 2)) is a joint probability density function over the range 0 < x < 5 and 0 < y < 2. Find V (X). Please report your answer to 3 decimal places.
1. Now generate y array using the function file my_func for the x array varying from...
1. Now generate y array using the function file my_func for the x array varying from 0 to 4 with an increment of 0.2. Generate x and y arrays without using any loop statement and do not print these arrays. 2. Off of question 1. Using MATLAB plot routine, plot y-array against the x-array generated in question 1. On this plot show grid lines, label the axes as x and y, and write the text ‘y=f(x)’ next to the plotted...
QUESTION : Given: fx,y(x,y)=be^-(x+y) for 0<x<a and 0<y<Infinity and =0 elsewhere a) Use Property 2 to...
QUESTION : Given: fx,y(x,y)=be^-(x+y) for 0<x<a and 0<y<Infinity and =0 elsewhere a) Use Property 2 to determine the value of b that will make this a valid density function. Ans: b=1/(1-e^-a) b) Use Property 3 to determine Fx,y(x,y) Ans: Fxy=(1-e^-x)(1-e^-y)/(1-e^-a) c) Take the derivative of Fx,y(x,y) to show that it equals fx,y(x,y). ANSWERS ARE GIVEN FOR A,B JUST PROVIDE THE STEPS Properties of Joint Distribution Functions: 2) ??,?(∞, ∞) = ? Example Given: ??,?(?, ?) = 0.2?(? − 1)?(? −...
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...
a) Define a function to be x^3+3x-4 and define another function to be x^2-5x+10. **Note: Use...
a) Define a function to be x^3+3x-4 and define another function to be x^2-5x+10. **Note: Use different names for each function. b) Plot both functions from part a on the same graph from x=-5 to x=5. Define a range of 0 to 100 with the PlotRange option. Use the PlotLegends option to label the functions with their "Expressions". You may need to refer to the "Lab 3 Functions Continued" instructional notebook or the Documentation Center to see how options are...
1) What is a function? Give two examples 2) Solve x2−4=0 factorize 3) Graph following line...
1) What is a function? Give two examples 2) Solve x2−4=0 factorize 3) Graph following line y= -3x+1 4) Find the domain of following functions y= x3+x2−5x+10 Y=5X−1 5) Find the following limits limn→∞  n32n3    limn→2    1000n    Please provide all the steps!
1a. Find the domain and range of the function. (Enter your answer using interval notation.) f(x)...
1a. Find the domain and range of the function. (Enter your answer using interval notation.) f(x) = −|x + 8|   domain= range= 1b.   Consider the following function. Find the composite functions f ∘ g and g ∘ f. Find the domain of each composite function. (Enter your domains using interval notation.) f(x) = x − 3 g(x) = x2 (f ∘ g)(x)= domain = (g ∘ f)(x) = domain are the two functions equal? y n 1c. Convert the radian...
1). Consider the following function and point. f(x) = x3 + x + 3;    (−2, −7) (a)...
1). Consider the following function and point. f(x) = x3 + x + 3;    (−2, −7) (a) Find an equation of the tangent line to the graph of the function at the given point. y = 2) Consider the following function and point. See Example 10. f(x) = (5x + 1)2;    (0, 1) (a) Find an equation of the tangent line to the graph of the function at the given point. y =
Using R programming language, complete the following. 1. Generate the bivariate normal sample of size 100...
Using R programming language, complete the following. 1. Generate the bivariate normal sample of size 100 with parameters a. marginal mean of X equal to 1, b. marginal mean of Y equal to 2, c. marginal variance of X equal to 3, d. marginal variance of Y equal to 4, e. correlation between X and Y equal to -1/2. You can use the function mvrnorm(), first installing its package by the code if (! require ("MASS")) install.packages("MASS"); library ("MASS") 2....
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT