Info
此问题已关闭。 请重新打开它进行编辑或回答。
HELLO PLEASE COULD HELP ME HOW TO CONVERT THIS CODE TO MATLAB.
1 次查看(过去 30 天)
显示 更早的评论
function[L1;L2;U1;U2] = Cholesky(a; b; c)
n = length(a);
Diagonales = zeros(1; n);
Sub = zeros(1; n - 1);
if a(1) > 0 then
Diagonales(1) = sqrt(a(1));
Sub(1) = b(1)/Diagonales(1);
k = 2;
fin = 0;
while k <= n ^ fin == 0 do
if a(k) - Sub(k - 1)^2 > 0 then
Diagonales(k) = sqrt(a(k) - Sub(k -1)^2);
if Diagonales(k) = 0 ^ k < n then
Sub(k) = b(k)/Diagonales(k);
else if Diagonales(k) == 0 then
fprintf('Division por cero')
fin = 1;
end if
else
fprintf('Division por cero')
fin = 1;
end if
k = k + 1
end while
fprintf('Valor negativo en la posicion (1), no se puede ejecutar el metodo')
end if
1 个评论
回答(1 个)
Walter Roberson
2019-6-8
编辑:Walter Roberson
2019-6-8
function [L1, L2, U1, U2] = Cholesky(a, b, c)
n = length(a);
Diagonales = zeros(1, n);
Sub = zeros(1, n - 1);
if a(1) > 0
Diagonales(1) = sqrt(a(1));
Sub(1) = b(1)/Diagonales(1);
k = 2;
fin = 0;
while k <= n && fin == 0
if a(k) - Sub(k - 1)^2 > 0
Diagonales(k) = sqrt(a(k) - Sub(k -1)^2);
if Diagonales(k) = 0 && k < n
Sub(k) = b(k)/Diagonales(k);
elseif Diagonales(k) == 0
fprintf('Division por cero')
fin = 1;
else
fprintf('Division por cero')
fin = 1;
end
end
k = k + 1
end
fprintf('Valor negativo en la posicion (1), no se puede ejecutar el metodo')
end
I believe the code you posted is incorrect. I think it should have an else before the final fprintf() call. Furthermore it does not calculate L1, L2, U1, or U2 that are needed for outputs.
0 个评论
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!