I am trying to nest functions in matlab, so as to calculate the deteminant of a
ID: 3672447 • Letter: I
Question
I am trying to nest functions in matlab, so as to calculate the deteminant of a 9 x 9 matrix, using determinants of an 8 x 8, 7 x 7, and so on. I started small with a 3 x 3 and 2 x 2 matrix determinant functions, but am having trouble with the 3 x 3 calling the 2 x 2 determinant function. Thoughts? This is the program so far:
function d3 = det3(A)
x = 1;y = 1;i = 1;j = 1;sum = 0;z = 1;
for y = 1:3
for i = 2:3
for j = 1:3
if j == y
j = j + 1;
else
x = i - 1;
B(x,y) = A(i,j);
end
end
end
d = det2(B);
sum = sum + i*z*d;
z = z * (-1);
end
function d2 = det2(A)
d2 = (A(1,1)*A(2,2) - (A(1,2)*A(2,1));
end
d3 = sum;
end
Explanation / Answer
Hi, you can try my code:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.