clear all;
clc;
%Question 2: The two equations to be solved are x+2y=3 and 4x+5y=6
%we can convert these in a form AW=U
A = [[1 2]; [4 5]];
U = [3;6];
%Hence our solution would be
W=inv(A)*U;
%We need to check that inv(A) exists. Else if det(A) =0, it won't exist, and hence we can't find a unique solution.
disp('The determinant value is'); disp(det(A));
disp('And hence the solution is');
disp('x=');disp(W(1));
disp('y=');disp(W(2));
% We can verify this solution by multiplying matrices A and W. And a
% correct solution would give AW=U.
disp('U='); disp(A*W);
% Another approach is to use plots.
% We can plot two functions y1 = f(x) = (3-x)/2 and y2 = g(x) = (6-4x)/5;
x = -10:10;
y1 = (3-x)/2;
y2 = (6-4*x)/5;
plot(y1,x,y2,x);
grid on;