필터 지우기
필터 지우기

matlab error: matrix dimension must agree

조회 수: 2 (최근 30일)
Sat m
Sat m 2013년 3월 10일
i am trying to solve linear equation by SVD. i get the error, "matrix dimension must agree" at the line x = V*((U'*B)./diag(S));
this is the code
% question (6) part (1) ...[show how to use SVD to solve linear systems of
% equation
%how SVD is used to solve systems of linear equations
% we have taken a system of linear equation
a = 0.00:100.00;
b = 0.00:100.00;
c = 0.00:100.00;
d = 0.00:100.00;
p = 0.00:100.00;
q = 0.00:100.00;
A = [a b;c d];
B = [p;q];
prompt = 'enter a number';
a = input(prompt);
b = input(prompt);
c = input(prompt);
d = input(prompt);
p = input(prompt);
q = input(prompt);
%if A*x = B is a nxn linear system then
%SVD of A is
[U,S,V]=svd(A,0);
%solution of the equation A*x = B is
x = V*((U'*B)./diag(S));% if we multiply U, S, V transpose then with some rounding error, we get A.
%so US(V(transpose))=A, so USVt.x = B, so x = (USVt)t*B (where t is the
%transpose. so x = Ut.st.(vt)T*b. now U is orthogonal matrix so, Ut = U
%inverse or U'. S is diagonal matrix so St=diag(S) and (Vt)t= V
disp(x);
please let me know how to solve this

채택된 답변

Matt J
Matt J 2013년 3월 10일
Shouldn't A,B be created after the a,b,...q data are entered?
prompt = 'enter a number';
a = input(prompt);
b = input(prompt);
c = input(prompt);
d = input(prompt);
p = input(prompt);
q = input(prompt);
A = [a b;c d];
B = [p;q];
  댓글 수: 2
Matt J
Matt J 2013년 3월 10일
편집: Matt J 2013년 3월 10일
Or, if you are doing this for a sequence of a(i)...q(i)
a = 0.00:100.00;
b = 0.00:100.00;
c = 0.00:100.00;
d = 0.00:100.00;
p = 0.00:100.00;
q = 0.00:100.00;
f=@(z) reshape(z,1,1,[]);
As=[f(a),f(b);f(c) f(d)];
Bs=[f(p);f(q)];
for i=1:length(a)
A=As(:,:,i);
B=Bs(:,:,i);
etc...
end
Sat m
Sat m 2013년 3월 10일
thank you. it solved the problem. thank you

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

추가 답변 (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