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
Walter Roberson
2019년 6월 8일
Which language is that? It looks sort of like Maple but it is not Maple.
답변 (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!