Given the following system of equations:
a1x1 + b1x2 + c1x3 = d1
a2x1 + b2x2 + c2x3 = d2
a3x1 + b3x2 + c3x3 = d3
Write a MATLAB program to find solutions for : x1, x2 and x3. For any value of a1, a2, a3, b1, b2, b3, c1, c2, c3, d1, d2 and d3. Your program must ask the user to enter at run time the coefficients of your systems.
MATLAB code is given below in bold letters.
clc;
close all;
clear all;
% prompt the user to enter the coefficients
a1 = input('Enter a1: ');
a2 = input('Enter a2: ');
a3 = input('Enter a3: ');
b1 = input('Enter b1: ');
b2 = input('Enter b2: ');
b3 = input('Enter b3: ');
c1 = input('Enter c1: ');
c2 = input('Enter c2: ');
c3 = input('Enter c3: ');
d1 = input('Enter d1: ');
d2 = input('Enter d2: ');
d3 = input('Enter d3: ');
% Now solve the equations using matrix form
% define matrix A abs B as follows
A = [a1 a2 a3;b1 b2 b3;c1 c2 c3];
B = [d1;d2;d3];
if(det(A)==0)
error('The determinant of A is zero!!!');
else
x = A^1*B
end
command window:
Enter a1: 1
Enter a2: 2
Enter a3: 3
Enter b1: 4
Enter b2: 5
Enter b3: 6
Enter c1: 7
Enter c2: 8
Enter c3: 9
Enter d1: 10
Enter d2: 11
Enter d3: 12
x =
68 (x1)
167 (x2)
266 (x3)
Get Answers For Free
Most questions answered within 1 hours.