Disponível somente no TrabalhosFeitos
  • Páginas : 9 (2144 palavras )
  • Download(s) : 0
  • Publicado : 21 de dezembro de 2012
Ler documento completo
Amostra do texto
ID #:000580654

TASK 1: Evaluation of determinants by the cofactor technique
Matlab code with its statements
clear%This function clears the command window and removes items from the workspace freeing up the system memory%
clc%Tis functionclears the command windows from any error or junk %
a=input('Please enter a value for element1');%This prompt the user to enter a value for a%
b=input('Please enter a value for element2');%This prompt the user to enter a value for b%
c=input('Please enter a value for element3');%This prompt the user to enter a value for c%
d=input('Please enter a value for element4');%This prompt the user toenter a value for d%
e=input('Please enter a value for element5');%This prompt the user to enter a value for e%
f=input('Please enter a value for element6');%This prompt the user to enter a value for f%
g=input('Please enter a value for element7');%This prompt the user to enter a value for g%
h=input('Please enter a value for element8');%This prompt the user to enter a value for h%i=input('Please enter a value for element9');%This prompt the user to enter a value for i%

matrix_5=[a b c; d e f; g h i]%This forms the entered values as matrix%

The Cofactor Technique
cofactor=(a*((e*i)-(f*h)))-(b*((d*i)-(f*g)))+(c*((d*h)-(e*g)))%This is how to find the determinant by using the cofactor technic

The Determinant
determinant=det(matrix_5)%Using the det command to find thedetermint%

Explanation of the code writing above and statements for task 1.
The clear function
This function was used to clear the command windows and remove any items from the workspace by freeing the systems memory.
The clc function
I used the clc function to clear the command window from any errors generated during my debugging of my code any time I run it.
The Input function
This functionprompt a string on the screen, by letting the user enter an input from the keyboard, it also evaluates any expressions in the input, and returns the value in evalResponse. In my case it allows the user to enter a value for the output variable assigned to whatever is entered. Example a,b,c,d,e,f,g,h,I,j,k,l.
Whatever is entered is formed into a matrix by using square brackets [ ] andassigning to an output variable called matrix_5.
The cofactor technique
The cofactor technique is used to find the determinant without using the det command.The method starts by selecting the first row and finding the determinant for each of the columns selected. This will be properly explain in the by hand solution.
Alternative method of coding
I discovered that there were alternative methods offinding out my determinant by the cofactor technique and that is shown below. It explain as follows, instead of writing it in one line as in the original code above , I could have used the technique to find for each individual characteristic determinant of each column in the first row and summed the all three up.
cofactor_a = a*(e*i-h*f);
% How to calculate for the of the cofactor_a, (*) is byusing function for multiplication.

cofactor_d = d*(b*i-c*h);
% How to calculate for the of the cofactor_d, (*) is by using function for multiplication

cofactor_g = g*((b*f)-(e*c));
% How to calculate for the of the cofactor_g, (*) is by using function for multiplication
determinant_matrix_5 = cofactor_a-cofactor_d+cofactor_g
%This is the summation of the individual cofactors as oneSemi colon
The semi colons after the line of code is a function in matlab meaning it should not display the output.
Det command
This is the next step were I verified the cofactor technique with the det command, meaning, finding the determinant of the Matrix_5

I didn’t encounter any problem.
By hand technique
Assuming that the elements have values of
a=2, b=4, c=6, d=8, e=10,...
tracking img