我在 MATLAB 中有這段代碼:
function [out,f] = rec_det(a,n)
if(n==2)
out = a(1,1)*a(2,2)-a(2,1)*a(1,2);
else
for j=1:n
f = a(1,j);
a(1,:) = [];
a(:,3) = [];
out = out ((-1)^(1 n)*f* rec_det(a,n-1));
end
end
我在這一行出現錯誤“out = out ((-1)^(1 n) f rec_det(a,n-1));”。錯誤顯示“未定義的變數函式”但我沒有了解為什么會這樣。
我對 MATLAB 很陌生,所以請耐心等待。
uj5u.com熱心網友回復:
這應該有效:
function [out,f] = rec_det(a,n)
if(n==2)
out = a(1,1)*a(2,2)-a(2,1)*a(1,2);
else
s = 0;
for j=1:n
f = a(1,j);
a(1,:) = [];
a(:,3) = [];
s = s ((-1)^(1 n)*f* rec_det(a,n-1));
end
out = s;
end
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/468936.html
標籤:matlab
上一篇:Gradle下載舊的編譯依賴項
下一篇:在箱線圖上添加乳膠解釋器
