how to get 2 outputs of my function?

조회 수: 2 (최근 30일)
tim123
tim123 2019년 3월 23일
댓글: Star Strider 2019년 3월 23일
function [L,R]= LR(A)
R=A;
L=eye(size(A,1));
n=size(A,1);
for j=1:n-1
for i=(j+1):n
L(i,j)=R(i,j)/R(j,j);
R(i,:)=R(i,:)-L(i,j)*R(j,:);
end
end
end
Hi, i acually do not really understand, why I am only getting L, but not R,

채택된 답변

Star Strider
Star Strider 2019년 3월 23일
The reason is likely the way you are calling your ‘LR’ funciton.
If you request both outputs, your function will deliver them:
A = ... ;
[L,R] = LR(A)
That call should return both outputs.
  댓글 수: 3
tim123
tim123 2019년 3월 23일
k I forgot to change a mistake in my code, that i changed. It works!
Star Strider
Star Strider 2019년 3월 23일
You didn’t state the matrix you are using as an argument, or what output you want from your funciton.
This works when I run it:
A = magic(4);
[L,R]= LR(A)
returning:
L =
1 0 0 0
0.3125 1 0 0
0.5625 0.56627 1 0
0.25 1.3012 -3 1
R =
16 2 3 13
0 10.375 9.0625 3.9375
0 -8.8818e-16 -0.81928 2.4578
0 -2.6645e-15 0 -2.6645e-15
Your function may only work for square matrices. If that is the case, you need to test for that, and return the appropriate outputs from your function, including an error condition and notification if the matrix argument is not square.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by