필터 지우기
필터 지우기

Why do I get this error?

조회 수: 1 (최근 30일)
Tianlan Yang
Tianlan Yang 2021년 3월 18일
편집: Adam Danz 2021년 3월 19일
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

채택된 답변

Adam Danz
Adam Danz 2021년 3월 18일
편집: Adam Danz 2021년 3월 18일
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
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?
Adam Danz
Adam Danz 2021년 3월 19일
편집: Adam Danz 2021년 3월 19일
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개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by