Hi everybody,
-I'm trying to program the ordinary least squares method, and I must
solve this matrix system:
e = h - A* x
x is the unknown.
After the resolution of the system and when I try the verification, x
doesn't resolve it!
Why?
The program:
% ------------------------------------------
% ------------------------------------------
clc;
M = 1; % arbitrary
N = 5; % arbitrary
P = 5; % arbitrary but P >= Q
Q = 4; % arbitrary but P >= Q
e = zeros (M* (N+ P+ 1), 1); % arbitrary = 0
h = ones (M* (N+ P+ 1), 1); % arbitrary = ones
A = eye (M* (N+ P+ 1), P+ M* (Q+ 1)); % arbitrary = eye
x = ((A' * A)^(-1)) * (A' * (h- e)),
% the size of x is (P+ M* (Q+ 1), 1);
% (A' * A) to transform into a square matrix for inversion
e == (h - (A * x)),
% Normally after this, the result is 1
% Why it doesn't!?
% ------------------------------------------
% ------------------------------------------
Thanks in advance!
|
|
0
|
|
|
|
Reply
|
zaki_nabil (105)
|
3/16/2005 8:13:09 PM |
|
In article <eeff36b.-1@webx.raydaftYaTP>, "Zaki N."
<zaki_nabil@caramail.com> wrote:
> Hi everybody,
>
> -I'm trying to program the ordinary least squares method, and I must
> solve this matrix system:
>
> e = h - A* x
> x is the unknown.
>
> After the resolution of the system and when I try the verification, x
> doesn't resolve it!
> Why?
>
> The program:
> % ------------------------------------------
> clc;
>
> M = 1; % arbitrary
> N = 5; % arbitrary
> P = 5; % arbitrary but P >= Q
> Q = 4; % arbitrary but P >= Q
>
> e = zeros (M* (N+ P+ 1), 1); % arbitrary = 0
> h = ones (M* (N+ P+ 1), 1); % arbitrary = ones
> A = eye (M* (N+ P+ 1), P+ M* (Q+ 1)); % arbitrary = eye
>
> x = ((A' * A)^(-1)) * (A' * (h- e)),
> % the size of x is (P+ M* (Q+ 1), 1);
> % (A' * A) to transform into a square matrix for inversion
>
> e == (h - (A * x)),
> % Normally after this, the result is 1
> % Why it doesn't!?
> % ------------------------------------------
>
> Thanks in advance!
-----------
Hello Zaki,
Two things are wrong here. To begin with, you're requiring
e == (h - (A * x))
to be exactly true, which makes no allowance for round off errors. You
need to change this to allow an error within a certain judiciously
selected tolerance.
However, the main problem is that, in effect, there are eleven linear
equalities here but only ten variables in x to adjust. The idea in least
squares is to find the value of x which produces the smallest sum of
squares in the expression A*x-(h-e). In the above circumstances it will,
in general, be impossible to make it identically zero.
(Remove "xyzzy" and ".invalid" to send me email.)
Roger Stafford
|
|
0
|
|
|
|
Reply
|
ellieandrogerxyzzy (4732)
|
3/16/2005 9:09:56 PM
|
|
Thanks for your reply Roger.
-The problem isn't coming from the ordinary least squares method or
not.
We are in front of a problem of resolving a matrix system:
e = h - A* x
Where "x" is the unknown, and "h", "A", and "e" can be 'anything'
known.
After the resolution of the system and when I try the verification, x
doesn't resolve it!
Where is the mistake?
Please give me another method to resolve it.
-The program:
% ------------------------------------------
% ------------------------------------------
clc;
M = 1; % arbitrary
N = 5; % arbitrary
P = 5; % arbitrary but P >= Q
Q = 4; % arbitrary but P >= Q
e = zeros (M* (N+ P+ 1), 1); % arbitrary = 0
h = ones (M* (N+ P+ 1), 1); % arbitrary = ones
A = eye (M* (N+ P+ 1), P+ M* (Q+ 1)); % arbitrary = eye
x = ((A' * A)^(-1)) * (A' * (h- e)),
% the size of x is (P+ M* (Q+ 1), 1);
% (A' * A) to transform into a square matrix for inversion
e == (h - (A * x)),
% Normally after this, the result is 1
% Why it doesn't!?
% ------------------------------------------
% ------------------------------------------
|
|
0
|
|
|
|
Reply
|
zaki_nabil (105)
|
3/17/2005 7:40:37 AM
|
|
"Zaki N." <zaki_nabil@caramail.com> wrote in message
news:eeff36b.1@webx.raydaftYaTP...
> Thanks for your reply Roger.
>
> -The problem isn't coming from the ordinary least squares method or
> not.
> We are in front of a problem of resolving a matrix system:
>
> e = h - A* x
>
> Where "x" is the unknown, and "h", "A", and "e" can be 'anything'
> known.
>
> After the resolution of the system and when I try the verification, x
> doesn't resolve it!
For there to be a solution x to the system A*x = h (i.e. the e vector is
exactly the zero vector) you would need to be able to write h as a linear
combination of the columns of A -- the coefficients in the linear
combination are the elements of x. Note that no column of A contains a
nonzero value in the last element. Therefore, no matter what coefficients
you choose, the linear combination of the columns of A will always have a
zero as the last element of the resulting vector. Since h has a 1 as its
last element, we can't express h as a linear combination of the columns of A
and so the system A*x = h has no exact solution.
Since there is no solution x that satisfies A*x = h exactly, we try to solve
it in a least-squares sense -- minimize the norm of (A*x - h) [which is -e
in your terminology.] In this case, the x that minimizes this norm is the
ones vector that the code below produces. The residual (A*x - h) is:
[0; 0; 0; 0; 0; 0; 0; 0; 0; 0; -1]
The last element of the residual is always going to be -1, from the
explanation above. Therefore to minimize the norm, we minimize the
magnitudes of the other elements of the residual -- and 0 is as small as the
magnitudes can get.
> Where is the mistake?
There is no mistake.
> Please give me another method to resolve it.
Just a suggestion: don't use ^(-1) to invert your matrix. If you need to
invert the matrix, use the INV function. However, you don't need to invert
the matrix -- simply use the backslash operator (\) instead. See HELP
MLDIVIDE for more information on the backslash operator.
--
Steve Lord
slord@mathworks.com
>
> -The program:
>
> % ------------------------------------------
> % ------------------------------------------
> clc;
>
> M = 1; % arbitrary
> N = 5; % arbitrary
> P = 5; % arbitrary but P >= Q
> Q = 4; % arbitrary but P >= Q
>
> e = zeros (M* (N+ P+ 1), 1); % arbitrary = 0
> h = ones (M* (N+ P+ 1), 1); % arbitrary = ones
> A = eye (M* (N+ P+ 1), P+ M* (Q+ 1)); % arbitrary = eye
>
> x = ((A' * A)^(-1)) * (A' * (h- e)),
> % the size of x is (P+ M* (Q+ 1), 1);
> % (A' * A) to transform into a square matrix for inversion
>
> e == (h - (A * x)),
> % Normally after this, the result is 1
> % Why it doesn't!?
>
> % ------------------------------------------
> % ------------------------------------------
|
|
0
|
|
|
|
Reply
|
slord (13279)
|
3/17/2005 2:30:59 PM
|
|
Thank you!
Even if I didn't understood all your explanations!
|
|
0
|
|
|
|
Reply
|
zaki_nabil (105)
|
3/18/2005 9:31:36 AM
|
|
|
4 Replies
26 Views
(page loaded in 0.208 seconds)
Similiar Articles: Listbox GUI - comp.soft-sys.matlabBelow is the thing i have tried out for the code... please correct me what else i missed out... 1) I created a folder named "ImageFolder" and then i kip all my .wav ... matlab code for image fusion using PCA - comp.soft-sys.matlab ...... PCA(principal component analysis) but > iam not getting correct way to complete the code ... dont know how to do the feature matching. I have typed my code below, please ... Cmove Dicom code - comp.protocols.dicomI am pasting the method code for doing the cmove request in java. Can someone who is familiar or has done this please verify if my cmove code is correct? stop matlab from execution - comp.soft-sys.matlabBut I haven't really tried to incorporate this in my codes, fortunately ... mex to C code is impossible, but convert Matlab code to C code is possible. Please correct me if ... Correct code to get CPU usage - comp.os.ms-windows.programmer ...Hi everyone: I've been struggling to come up with a correct code to determine CPU ... iCode Systems (Replies direct to my email address will be ignored. Please ... Please Fix My Macro - comp.cad.solidworksWould someone please modify my macro to make it ... In the meantime, you can correct it, and publish it anywhere, as long as I have access to the final code. Please let me ... Closing a database - comp.databases.mysqlHowever, from what it seems (and please correct me if my understanding is in error), the "use ... DDE EXCEL close the file - comp.soft-sys.sas Hello All, I'm running a code ... Information required on projected 3D graphical objects - comp ...I am looking for either a library or an open source code which can help me ... Please correct if I am wrong? The geometry is 3D, however when rendering the geometry ... recvfrom returns with an error code of 14, EFAULT "Bad Address ...Please DON'T copy followups to me -- I'll assume it wasn't posted to the group. ... Whenever I try to > > It looks like you didn't post the correct code, I don't see any ... italics label in legend - comp.soft-sys.matlabHi, here is my code for the legend: legend ... (BTW, please don't toppost--hard follow conversation makes...) ... Typographically, the correct thing is to set only the 't ... Please correct my c++ Code - C / C++Please correct my c++ Code. C / C++ Forums on Bytes. ... ///// LinkList.cpp #include "LinkList.h" /* The LinkList class implementation*/ help me rss error in my code please correct this code.Hi friends. i need ur help, in my project i create a rss using syndication, i am using database . title, date, description all mostly run , but links is ... 7/23/2012 6:17:26 PM
|