11221 212211 212 12 1
10 次查看(过去 30 天)
显示 更早的评论
回答(1 个)
Jan
2019-11-7
编辑:Jan
2019-11-7
Please post an exact copy of the error message in the forum. A rough paraphrasing will hide important details. Thanks.
I assume the error message tells you, that you did not call this function with an input argument. How did you start the code? Using the "Run" button? Then no input is provided.
A simplification of your code:
function [determinant , inverse ] = invanddet3by3(A)
%INVANDDET3BY3 Calculates the determinant and the inverse of a 3 X 3 matrix by using cofactors and adjoint matrix
A11 = invanddet2by2sol(A([2,3], [2,3])); % Cofactors 3x3 matrix A
A12 = -invanddet2by2sol(A([2,3], [1,3]));
A13 = invanddet2by2sol(A([2,3], [1,2]));
A21 = -invanddet2by2sol(A([1,3], [2,3]));
A22 = invanddet2by2sol(A([1,3], [1,3]));
A23 = -invanddet2by2sol(A([1,3], [1,2]));
A31 = invanddet2by2sol(A([1,2], [2,3]));
A32 = -invanddet2by2sol(A([1,2], [1,3]));
A33 = invanddet2by2sol(A([1,2], [1,2]));
J = [ A11 A12 A13; A21 A22 A23; A31 A32 A33]; % Adjugate Matrix
determinant = A(1,1) * A11 + A(1,2) * A12 + A(1,3) * A13; % Determinant of A
if determinant ~= 0
inverse = J' / determinant; % Inverse of A
else
inverse=[];
end
end
4 个评论
Steven Lord
2019-11-7
How was A defined before you executed this line of code?
invanddet3by3(invandet2by2sol(A))
If it hadn't been defined before you executed that line, MATLAB can't know what matrix you want to pass into the invanddet2by2sol function.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Calendar 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!