Why do I get this error?
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示

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
採用された回答
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!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)
