Azzera filtri
Azzera filtri

Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

HELLO PLEASE COULD HELP ME HOW TO CONVERT THIS CODE TO MATLAB.

1 visualizzazione (ultimi 30 giorni)
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

Risposte (1)

Walter Roberson
Walter Roberson il 8 Giu 2019
Modificato: Walter Roberson il 8 Giu 2019
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.

Questa domanda è chiusa.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by