Write a MATLAB program that asks the user to input the co-ordinates of 3 points
ID: 3575638 • Letter: W
Question
Write a MATLAB program that asks the user to input the co-ordinates of 3 points as a 3x2 matrix: [x1 y1; x2 y2; x3 y3]. Then: 1. Find the quadratic expression of the form y(x) = Ax2 + Bx + C that satisfies all 3 points
and display the values of A, B, and C. Check to make sure that no two values of x1, x2, x3 are the same. All x1, x2, x3 have to be distinct. 2. Plot the function over the entire range covering x1, x2, x3. Do not use loops. Use only array operations. Make sure to choose the order of x1, x2, and x3 depending upon the actual values that the user enters. (The user may enter them in any order: not necessarily such that x1 < x2 < x3). Hint: The quadratic expression Ax2 + Bx + C can be found by solving the following system of equations for A, B, and C:
A (x1)2 + Bx1 + C = y1
A (x2)2 + Bx2 + C = y2
A (x3)2 + Bx3 + C = y3
Explanation / Answer
syms A B C
m = input('Enter a 3X2 matrix: ');
x1 = m(1,1);
y1 = m(1,2);
x2 = m(2,1);
y2 = m(2,2);
x3 = m(3,1);
y3 = m(3,2);
eqn1 = A*x1.^2 + B*x1 + C == y1;
eqn2 = A*x2.^2 + B*x2 + C == y2;
eqn3 = A*x3.^2 + B*x3 + C == y3;
[A,B] = equationsToMatrix([eqn1, eqn2, eqn3], [x, y, z]);
X = linsolve(A,B);
A = X(1)
B = X(2)
C = X(3)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.