Why do I get this error?
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천

Here is the function:
function [X1,X2,X] = msystem(A,B)
[~,n] = size(A);
[~,p] = size(B);
[L,U] = lu(A);
%solving for X1
X1 = inv(A)*B;
invL = [L eye(n)];
invL = rref(invL);
invL = invL(:,(n+1:n*2));
Y = invL*B;
invU = [U eye(n)];
invU = rref(invU);
invU = invU(:,(n+1:n*2));
X2 = invU * Y;
X = Y ./ U;
if (closetozeroroundoff(X1 - X2) == zeros(n,p))
disp('The solutions are the same')
else
disp('An error has been made on this exercise')
end
if (closetozeroroundoff(X1 - X) == zeros(n,p))
disp('The solutions are the same')
else
disp('An error has been made on this exercise')
end
end
채택된 답변
0 개 추천
closetozeroroundoff(), a 3rd party function not defined in the question, contains more than one input and one of the inputs is apparently named H or p. However, you're only providing 1 input so H or p is not defined in the function.
댓글 수: 11
Tianlan Yang
2021년 3월 18일
Could you please show me how to edit it?
Adam Danz
2021년 3월 18일
I can't because I don't know what closetozeroroundoff is, I don't know how many inputs there are, and I don't know what the inputs should be.
In this line,
if (closetozeroroundoff(X1 - X2) == zeros(n,p))
you are only providing one input to the function. That's not enough inputs. So, open the file containing closetozeroroundoff and look at how many inputs there should be in the first line of code. If you're lucky, the file may contain documentation that explains what the inputs should be.
Tianlan Yang
2021년 3월 18일
I try to use if (closetozeroroundoff(X1 - X2,7) == zeros(n,p)), solve this problem, but there is another error, how to print out the different dimension matrix?

Adam Danz
2021년 3월 18일
I encourage you to learn how to use debug mode so you can independently solve these kinds of problems.
The error message tells you the function and line number that fails. You can put a break point on that line (see link above) and then look at the size of Y and U using
size(Y)
size(U)
You'll see that they have different sizes.
The error message tells you that their dimensions must agree for that operation.
Note that the sizes of A and B match the sizes of Y and U so, without looking at the code, I'd bet that the sizes of A and B should also be the same. I bet this would not throw any errors,
A = magic(5); B = randi(10,5,5)
but most importantly, is that what the inputs should be and is the code doing what you intend it to do? Those are questions you need to answer as the developer of the program.
Tianlan Yang
2021년 3월 18일
Thank you so much! I think I understand what you mean. I have another similar question but with different error, could you please help me to see this? Thank you so much!

Here is the function:
function [L,U] = eluinv(A)
[~,n]=size(A);
[L,U] = lu(A)
LU = roundingfixer(L*U);
if (A == LU)
disp('LU factorization is valid')
else
disp('A mistake was made somewhere.')
end
if (rank(U) == rank(A))
disp('U is an echelon form of A')
else
disp('U is not an echelon form of A? What is wrong?!')
end
if (rank(A) == n)
invL = [L eye(n)];
invU = [U eye(n)];
invL = rref(invL);
invU = rref(invU);
invL = invL(:,(n+1:n*2));
invU = invU(:,(n+1:n*2));
invA = roundingfixer(invU * invL)
P = roundingfixer(inv(A))
disp('the inverse of A calculated using LU factorization is')
disp(invA)
if (invA == P)
disp('Yes, LU factorization works for calculating the inverses')
else
disp('LU factorization does not work for me!?')
end
else
sprintf('A is not invertible')
invA = [];
end
end
Adam Danz
2021년 3월 18일
Same comment as above.
The error message tells you which line is the problem.
That line is trying to horizontally concatenate two variables but one variable is 4x3 and the other is 3x3 but horizontal concatenation requires the same number of rows.
Tianlan Yang
2021년 3월 18일
Yes, I got your idea. I want to know if they have different number of rows, how to adjust it to make it run.(Maybe a function that can replace horizontally concatenate?)
Adam Danz
2021년 3월 19일
It looks like A needs to be a square matrix.
Tianlan Yang
2021년 3월 19일
Can you show me how to convert A the 3*4 trasnpose to a square matrix?
Tianlan Yang
2021년 3월 19일
For example, if a matrix is 4*3 [1 2 3; 4 5 6; 7 8 9; 10 11 12], how to make it look like 4*4?
That's like asking how to make this cube look like a circle. A 4x3 matrix can never look like a 3x3 matrix without changing the data. You can remove the first row, second row, third row, or 4th row of the 4x3 matrix but now it's a completely different variable.

m = (1:4)'.*ones(1,3)
m = 4×3
1 1 1
2 2 2
3 3 3
4 4 4
m(3,:) = [] % remove 3rd row
m = 3×3
1 1 1
2 2 2
4 4 4
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Linear Algebra에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
