In: Advanced Math
Example #2: Write the following set of four linear equations with 4 unknowns x1, x2, x3, and x4 in the matrix form. Solve the equations using MATLAB.
0.1 x1+ 2.3 x2 + 3x3 + 4x4 =1
x1+ 3x2 -7x3 +5x4 =2
3x1+2x2+7x3 =3
x1 +2x2 +x3 +10x4=0
(b)Roots of Polynomials:
In order to obtain the roots of a polynomial with the coefficients a1,a2,a3 ,... (where a1 is the coefficient of the highest power, and so on in a descending order) using MATLAB, organize the coefficients of the equation using the following format: p=[a1, a2, a3, a4]
Then the roots (all the roots - real and complex) can be obtain by the following command: r=roots(p)
%Matlab code for solving
clear all
close all
%finding coefficients for Matrix
A=[0.1 2.3 3 4; 1 3 -7 5; 3 2 7 0;1 2 1 10];
fprintf('Coefficient Matrix is\n')
disp(A)
%b vector is
b=[1;2;3;0];
fprintf('b vector is \n')
disp(b)
%Hence unknowns are
x=A\b;
fprintf('The unknowns are x1=%f, x2=%f, x3=%f,
x4=%f\n',x(1),x(2),x(3),x(4))
%roots of polynomial
a=[4 3 2 1];
fprintf('\nHere a1=%f; a2=%f; a3=%f;
a4=%f\n',a(1),a(2),a(3),a(4))
fprintf('\n\tRoots for a1x^3+a2x^2+a3*x+a4=\n')
p=roots(a);
disp(p)
%%%%%%%%%%%%%%%% End of Code %%%%%%%%%%%%%%