Create a Matlab Mfile to solve an nn system of equations usi
Create a Matlab M-file to solve an n*n system of equations using Cramer’s method. It should be a function which takes coefficients of the system and constant terms as user input and gives the values of unknowns.
Solution
program:
clc
 clear all
 n=input(\' enter number of variables\');
 e=input(\'number of equations\');
 if (n>e || n<e),
     disp(\'system is inconsisstent\');
 else
     disp(\'system is consisstent\');
     disp(\'enter the constants of the equation one bye one\')
     for i=1:n,
         for j=1:n,
             A(i,j)=input(\'enter the coeficents one by one=\');
         end
         b(i)=input(\'enter equation right side constant=\');
         disp(\'go for the next equation\');
     end
     if det(A)==0,
         disp(\'no solution\');
     else
     for i=1:n,
         s=A;
         s(:,i)=b;
         x(i)=(det(s)/det(A));
         disp(\'x\');
     disp(x);
     end
     end
   
 end
result:
enter number of variables2
 number of equations2
 system is consisstent
 enter the constants of the equation one bye one
 enter the coeficents one by one=1
 enter the coeficents one by one=2
 enter equation right side constant=3
 go for the next equation
 enter the coeficents one by one=4
 enter the coeficents one by one=5
 enter equation right side constant=6
 go for the next equation
 x
     -1
x
     -1     2
>>

