The graph of the function y = ax^4 + bx^3 + cx^2 + dx + e passes through five po
ID: 3864266 • Letter: T
Question
The graph of the function y = ax^4 + bx^3 + cx^2 + dx + e passes through five points in the format (x, y). Ask the user to enter as a matrix the coordinates of five points where each row corresponds to one of the five points, (x, y). As an example, the points (-4, -7.6), (-2, -17.2), (0.2, 9.2), (1, -1.6), and (4, -36.4) would be entered by the user as: [-4, -7.6; -2, -17.2; 0.2, 9.2; 1, -1.6; 4, -36.4] The result will be a 5 times 2 matrix with x-coordinates in the first column and y coordinates in the second. Determine the constants a, b, c, d, and e. Write a system of five equation with five unknowns and use MATLAB to solve the equations. a = 0.50 b = -0.10 c = -10.00 d = -2.00 e = 10.00Explanation / Answer
Please find the code and output below.
CODE:
findConstants.m
------------------------------------
function findConstants()
% get the coordinates
% This code only works for the equation of type -
% y = ax^4 + bx^3 + cx^2 + dx + e
cd=input('enter x,y coordinates ');
% Create a matrix for X.
% Since the coefficient of e in the equation is 1, the fifth column
% of every row is fixed to 1.
X=[ cd(1,1)^4, cd(1,1)^3, cd(1,1)^2, cd(1,1),1
cd(2,1)^4, cd(2,1)^3, cd(2,1)^2, cd(2,1),1
cd(3,1)^4, cd(3,1)^3, cd(3,1)^2, cd(3,1),1
cd(4,1)^4, cd(4,1)^3, cd(4,1)^2, cd(4,1),1
cd(5,1)^4, cd(5,1)^3, cd(5,1)^2, cd(5,1),1];
% Create a Y matrix from the coordinates information.
Y = [cd(1,2); cd(2,2); cd(3,2); cd(4,2); cd(5,2)];
% To find the constants - a,b,c,d and e, use the equation of the form
% Ax = B, here x = A.
% Similarly in our case, A is X and b is Y.
constnts = XY;
a = constnts(1)
b = constnts(2)
c = constnts(3)
d = constnts(4)
e = constnts(5)
end
--------------------------------------
OUTPUT:
>> findConstants
enter x,y coordinates
[-4,-7.6; -2, -17.2; 0.2,9.2;1,-1.6;4,-36.4]
a =
0.5000
b =
-0.1000
c =
-10.0000
d =
-2.0000
e =
10
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.