Question

Using Matlab to solve the problem below Given X=[-2 -1 0 1 2] Y=[1.5 3.2 4.5...

Using Matlab to solve the problem below

Given

X=[-2 -1 0 1 2]

Y=[1.5 3.2 4.5 3.4 2]

a). Plot a scatter plot of the data

b). Determine the coefficients of the polynomial ?0 + ?1? + ?2?2 which best fits the data

c). Plot this function on the same plot as in part ‘a’.

USE MATLAB CODE ONLY!
USE MATLAB CODE ONLY!

THANK YOU

Homework Answers

Answer #1

MATLAB Code:

close all
clear
clc

% To get the coefficients of the quadratic function,
% y = a0 + a1*x + a2*x^2;
% We need to solve the system AX = y,
% where:
% A = [1 x x^2] and X = [a0 a1 a2]

% Data points
x = [-2 -1 0 1 2]';
y = [1.5 3.2 4.5 3.4 2]';
A = [ones(size(x)) x x.^2];
X = A\y; % Solve the system
fprintf('Quadratic Function, y = (%.4f) + (%.4f)*x + (%.4f)*x^2\n', X)

% Plotting
xq = linspace(min(x), max(x), 100); % Bunch of new samples for a smoother plot
yq = X(1) + X(2)*xq + X(3)*xq.^2;
plot(x, y, 'o', xq, yq)
xlabel('x'), ylabel('y')
title('Polynomial Curve Fitting')
legend('Data Points', 'Polynomial Fit', 'Location', 'south')

Output:

Quadratic Function, y = (4.1486) + (0.1200)*x + (-0.6143)*x^2

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
MATLAB CODE REQUIRED Consider the problem of estimating y(0.5) for the boundary-value problem y''+ y' =...
MATLAB CODE REQUIRED Consider the problem of estimating y(0.5) for the boundary-value problem y''+ y' = y + 2, y(0) = 0, y'(1) = 2. Find the solution using 2 approaches: (b) Use finite difference with n = 10.Please provide Matlab code. What is y(0.5) value with Matlab? (c) Using bvp4c. Please provide Matlab code. What is y(0.5) value with Matlab?
Using MATLAB Write a user-defined MATLAB function for the following math function: y(x)= (-0.2x^3 + 7x^2)e^-0.3x...
Using MATLAB Write a user-defined MATLAB function for the following math function: y(x)= (-0.2x^3 + 7x^2)e^-0.3x The input to the function is x and the output is y. Write the function such that x can be a vector (use element-by-element operations). (a) Use the function to calculate y(-1.5) and y(5). (b) Use the function to make a plot of the function y(x) for -2 ≤ x ≤ 6.
Use MATLAB to find the best a, b, and c coefficients for curve y=a*(sqrt(x)/x)+bx+c to fit...
Use MATLAB to find the best a, b, and c coefficients for curve y=a*(sqrt(x)/x)+bx+c to fit these data points: (x,y)=[(0.1 2.5) (1.2 1.64) (2.1 1.67) (3.35 1.81) (4.5 1.9)] Use fprintf to show the a,b,c values you obtained, also plot the points and fitted curve in one plot (use proper labels.)
Let X ∼ N(0, 1), ∼ N(0, 1). Let Y = 1.75 + 2X + ....
Let X ∼ N(0, 1), ∼ N(0, 1). Let Y = 1.75 + 2X + . Generate 100 samples for (X, Y ). Use the generated data to fit a linear regression. (a) Report the fitted coefficients and intercept. (b) Draw a scatter plot of (X, Y ). Add the fitted line and the real line to the scatter plot with different color. Using R
Solve the given LDE using the method of undetermined coefficients. y'''-y'=4e^-x+3e^2x; y(0)=0, y'(0)=-1, y''(0)=2
Solve the given LDE using the method of undetermined coefficients. y'''-y'=4e^-x+3e^2x; y(0)=0, y'(0)=-1, y''(0)=2
Solve the given LDE using the method of undetermined coefficients. y'''-y'=4e^-x+3e^2x; y(0)=0, y'(0)=-1, y''(0)=2
Solve the given LDE using the method of undetermined coefficients. y'''-y'=4e^-x+3e^2x; y(0)=0, y'(0)=-1, y''(0)=2
Solve the given initial-value problem. y'' + x(y')2 = 0, y(1) = 5, y'(1) = 2...
Solve the given initial-value problem. y'' + x(y')2 = 0, y(1) = 5, y'(1) = 2 y =
Curve-Fit Function USING MATLAB Using the top-down design approach, develop a MATLAB function A8P2RAlastname.m that reads...
Curve-Fit Function USING MATLAB Using the top-down design approach, develop a MATLAB function A8P2RAlastname.m that reads data from a file and performs regression analysis using polyfit and polyval. The function shall have the following features: The input arguments shall include the file name (string), a vector of integers for the degrees of polynomial fits to be determined, and an optional plot type specifier (‘m’ for multiple plots, ‘s’ for a single plot - default). The data files will be text...
Using the method of undetermined coefficients, solve the following Initial Value Problem. y'' - y =...
Using the method of undetermined coefficients, solve the following Initial Value Problem. y'' - y = (t)(e^t)    ; y(0) = 0 ; y(-1) = e - 1/e Please write clearly! Thank you!
Solve in Matlab please. An ltic system is specified by the eq: D(D+1) y(t) = (D+2)x(t)...
Solve in Matlab please. An ltic system is specified by the eq: D(D+1) y(t) = (D+2)x(t) a) Find the characteristic polynomial, char. equation, char. roots, and char. modes. b) find y0(t), zero-input component of the response y(t) for t>=o; if initial conditions is y0(0-) =  y'0(0-) = 1
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT