Info
This question is closed. Reopen it to edit or answer.
HELLO PLEASE COULD HELP ME HOW TO CONVERT THIS CODE TO MATLAB.
1 view (last 30 days)
Show older comments
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 Comment
Walter Roberson
on 8 Jun 2019
Which language is that? It looks sort of like Maple but it is not Maple.
Answers (1)
Walter Roberson
on 8 Jun 2019
Edited: Walter Roberson
on 8 Jun 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.
0 Comments
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!