Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
solve command

Subject: solve command

From: Shane

Date: 24 Mar, 2009 07:34:03

Message: 1 of 21

Hi,
i hav got the following matter:
i need a solve commend in matlab for the equation "A*(R*x)-b=0".
A and R are a (n x n) matrix and b is a column vector. x is also a column vector, which has got n different variables, and is demanded.
Can anyone help me?

Shane

Subject: solve command

From: us

Date: 24 Mar, 2009 09:12:01

Message: 2 of 21

"Shane"
> i need a solve commend in matlab for the equation "A*(R*x)-b=0".
> A and R are a (n x n) matrix and b is a column vector. x is also a column vector, which has got n different variables, and is demanded...

one of the solutions

     f=sym('a*(b*x)-c=0');
     a=magic(3);
     b=magic(3);
     c=magic(3);
     fs=solve(f);
     r=subs(fs,{'a','b','c'},{a,b,c})
%{
% r =
        0.125 1 0.16667
      0.33333 0.2 0.14286
         0.25 0.11111 0.5
%}
% check
     a.*(b.*r)-c
%{
% ans =
     0 0 0
     0 0 0
     0 0 0
%}

us

Subject: solve command

From: Roger Stafford

Date: 24 Mar, 2009 17:32:16

Message: 3 of 21

"Shane " <black.gentz@hotmail.de> wrote in message <gqa2db$rhj$1@fred.mathworks.com>...
> Hi,
> i hav got the following matter:
> i need a solve commend in matlab for the equation "A*(R*x)-b=0".
> A and R are a (n x n) matrix and b is a column vector. x is also a column vector, which has got n different variables, and is demanded.
> Can anyone help me?
> Shane

  I am not sure what your problem is, Shane. Matrix multiplication obeys the associative law, so A*(R*x) is equal to (A*R)*x. Why not just do this:

 x = (A*R)\b;

It is a standard problem of n linear equations in n unknowns. If A*R is non-singular it has a unique solution.

Roger Stafford

Subject: solve command

From: Shane

Date: 25 Mar, 2009 08:37:01

Message: 4 of 21

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <gqb5f0$cuc$1@fred.mathworks.com>...
 
> I am not sure what your problem is, Shane. Matrix multiplication obeys the associative law, so A*(R*x) is equal to (A*R)*x. Why not just do this:
>
> x = (A*R)\b;
>
> It is a standard problem of n linear equations in n unknowns. If A*R is non-singular it has a unique solution.
>
> Roger Stafford

my problem is, that i cant build up the inverse matrix of R and therefor i need a solve command.

Subject: solve command

From: Torsten Hennig

Date: 25 Mar, 2009 09:01:39

Message: 5 of 21

> "Roger Stafford"
> <ellieandrogerxyzzy@mindspring.com.invalid> wrote in
> message <gqb5f0$cuc$1@fred.mathworks.com>...
>
> > I am not sure what your problem is, Shane.
> Matrix multiplication obeys the associative law, so
> o A*(R*x) is equal to (A*R)*x. Why not just do this:
> >
> > x = (A*R)\b;
> >
> > It is a standard problem of n linear equations in n
> unknowns. If A*R is non-singular it has a unique
> solution.
> >
> > Roger Stafford
>
> my problem is, that i cant build up the inverse
> matrix of R and therefor i need a solve command.

x = (A*R)\b _is_ the command to solve the equation
A*(R*x) - b = 0 for x.

Of course, you could also solve in two steps for x:
y = A\b
x = R\y.

Best wishes
Torsten.

Subject: solve command

From: Shane

Date: 25 Mar, 2009 09:27:01

Message: 6 of 21

Torsten Hennig <Torsten.Hennig@umsicht.fhg.de> wrote in message <30971896.1237971730030.JavaMail.jakarta@nitrogen.mathforum.org>...
> > "Roger Stafford"
> > <ellieandrogerxyzzy@mindspring.com.invalid> wrote in
> > message <gqb5f0$cuc$1@fred.mathworks.com>...
> >
> > > I am not sure what your problem is, Shane.
> > Matrix multiplication obeys the associative law, so
> > o A*(R*x) is equal to (A*R)*x. Why not just do this:
> > >
> > > x = (A*R)\b;
> > >
> > > It is a standard problem of n linear equations in n
> > unknowns. If A*R is non-singular it has a unique
> > solution.
> > >
> > > Roger Stafford
> >
> > my problem is, that i cant build up the inverse
> > matrix of R and therefor i need a solve command.
>
> x = (A*R)\b _is_ the command to solve the equation
> A*(R*x) - b = 0 for x.
>
> Of course, you could also solve in two steps for x:
> y = A\b
> x = R\y.
>
> Best wishes
> Torsten.


I hav tried this sloution method, but the problem is tht the condition of A-matrix is very bad and the det(R)=0. So this solution causes to no results.

Subject: solve command

From: Torsten Hennig

Date: 25 Mar, 2009 09:37:52

Message: 7 of 21

> Torsten Hennig <Torsten.Hennig@umsicht.fhg.de> wrote
> in message
> <30971896.1237971730030.JavaMail.jakarta@nitrogen.math
> forum.org>...
> > > "Roger Stafford"
> > > <ellieandrogerxyzzy@mindspring.com.invalid> wrote
> in
> > > message <gqb5f0$cuc$1@fred.mathworks.com>...
> > >
> > > > I am not sure what your problem is, Shane.
> > > Matrix multiplication obeys the associative law,
> so
> > > o A*(R*x) is equal to (A*R)*x. Why not just do
> this:
> > > >
> > > > x = (A*R)\b;
> > > >
> > > > It is a standard problem of n linear equations
> in n
> > > unknowns. If A*R is non-singular it has a unique
> > > solution.
> > > >
> > > > Roger Stafford
> > >
> > > my problem is, that i cant build up the inverse
> > > matrix of R and therefor i need a solve command.
> >
> > x = (A*R)\b _is_ the command to solve the equation
> > A*(R*x) - b = 0 for x.
> >
> > Of course, you could also solve in two steps for x:
> > y = A\b
> > x = R\y.
> >
> > Best wishes
> > Torsten.
>
>
> I hav tried this sloution method, but the problem is
> tht the condition of A-matrix is very bad and the
> det(R)=0. So this solution causes to no results.

If an exact solution of the equation A*(R*x) - b = 0
exists, x = (A*R)\b will produce it.
Otherwise, x will be an "approximate" solution, i.e.
a vector which minimizes the "error" A*(R*x) - b in the Euclidean norm.

Best wishes
Torsten.

Subject: solve command

From: Torsten Hennig

Date: 25 Mar, 2009 10:09:04

Message: 8 of 21

> > Torsten Hennig <Torsten.Hennig@umsicht.fhg.de>
> wrote
> > in message
> >
> <30971896.1237971730030.JavaMail.jakarta@nitrogen.math
>
> > forum.org>...
> > > > "Roger Stafford"
> > > > <ellieandrogerxyzzy@mindspring.com.invalid>
> wrote
> > in
> > > > message <gqb5f0$cuc$1@fred.mathworks.com>...
> > > >
> > > > > I am not sure what your problem is, Shane.
> > > > Matrix multiplication obeys the associative
> law,
> > so
> > > > o A*(R*x) is equal to (A*R)*x. Why not just
> do
> > this:
> > > > >
> > > > > x = (A*R)\b;
> > > > >
> > > > > It is a standard problem of n linear
> equations
> > in n
> > > > unknowns. If A*R is non-singular it has a
> unique
> > > > solution.
> > > > >
> > > > > Roger Stafford
> > > >
> > > > my problem is, that i cant build up the
> inverse
> > > > matrix of R and therefor i need a solve
> command.
> > >
> > > x = (A*R)\b _is_ the command to solve the
> equation
> > > A*(R*x) - b = 0 for x.
> > >
> > > Of course, you could also solve in two steps for
> x:
> > > y = A\b
> > > x = R\y.
> > >
> > > Best wishes
> > > Torsten.
> >
> >
> > I hav tried this sloution method, but the problem
> is
> > tht the condition of A-matrix is very bad and the
> > det(R)=0. So this solution causes to no results.
>
> If an exact solution of the equation A*(R*x) - b = 0
> exists, x = (A*R)\b will produce it.
> Otherwise, x will be an "approximate" solution, i.e.
> a vector which minimizes the "error" A*(R*x) - b in
> the Euclidean norm.
>
> Best wishes
> Torsten.

As I read in the MATLAB documentation, the backslash
operation does not seem to produce a least-squares
solution in the case of square systems if the coefficient
matrix is singular.

Instead, you can try
x = pinv(A*R)*b

Best wishes
Torsten.

Subject: solve command

From: Bruno Luong

Date: 25 Mar, 2009 10:32:02

Message: 9 of 21

Torsten Hennig <Torsten.Hennig@umsicht.fhg.de> wrote in message <29391649.1237975774607.JavaMail.jakarta@nitrogen.mathforum.org>...

>
> As I read in the MATLAB documentation, the backslash
> operation does not seem to produce a least-squares
> solution in the case of square systems if the coefficient
> matrix is singular.
>
> Instead, you can try
> x = pinv(A*R)*b
>
> Best wishes
> Torsten.

Hi Torsen,

Yes, the backslash actually produces the least-square solution for overdetermined system (minimizing the norm of the residual, on the image space), as with pinv.

However if the matrix has non-trivial kernel (different {0}), then backslash selects a solution that is usually not the minimum-norm solution (minimize the norm on the source space, but sill least-square solution). This is the main difference between pinv.

Hope it is clear,

Bruno

Subject: solve command

From: Shane

Date: 25 Mar, 2009 11:47:01

Message: 10 of 21

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <gqd172$fp1$1@fred.mathworks.com>...
> Torsten Hennig <Torsten.Hennig@umsicht.fhg.de> wrote in message <29391649.1237975774607.JavaMail.jakarta@nitrogen.mathforum.org>...
>
> >
> > As I read in the MATLAB documentation, the backslash
> > operation does not seem to produce a least-squares
> > solution in the case of square systems if the coefficient
> > matrix is singular.
> >
> > Instead, you can try
> > x = pinv(A*R)*b
> >
> > Best wishes
> > Torsten.
>
> Hi Torsen,
>
> Yes, the backslash actually produces the least-square solution for overdetermined system (minimizing the norm of the residual, on the image space), as with pinv.
>
> However if the matrix has non-trivial kernel (different {0}), then backslash selects a solution that is usually not the minimum-norm solution (minimize the norm on the source space, but sill least-square solution). This is the main difference between pinv.
>
> Hope it is clear,
>
> Bruno


Thanks for the clearings.
I tried to built the A Matrix in another way. So the new equation is A*x=B.
But when I try to solve this problem with x=A\B or x=inv(A)*B, then the results is not quite correct. I guess it must be a rounding error or something like that.
Is it possible solve this problem in another way, e.g. an iteration method??

Shane

Subject: solve command

From: Torsten Hennig

Date: 25 Mar, 2009 11:42:22

Message: 11 of 21

>
> Hi Torsen,
>
> Yes, the backslash actually produces the least-square
> solution for overdetermined system (minimizing the
> norm of the residual, on the image space), as with
> pinv.
>
> However if the matrix has non-trivial kernel
> (different {0}), then backslash selects a solution
> that is usually not the minimum-norm solution
> (minimize the norm on the source space, but sill
> least-square solution). This is the main difference
> between pinv.
>
> Hope it is clear,
>
> Bruno

Hi Bruno,

cited from MATLAB documentation for square matrices:

http://www.mathworks.com/access/helpdesk/help/techdoc/index.html?/access/helpdesk/help/techdoc/math/f4-983672.html&http://www.google.de/search?hl=de&q=matlab+%26+linear+equations&meta=

"If A is singular, the solution to Ax = b either does not exist, or is not unique. The backslash operator, A\b, issues a warning if A is nearly singular and raises an error condition if it detects exact singularity."

So in the case A is singular, a solution with the
backslash operator (either exact or in the least-squares sense) can not be obtained ?

Best wishes
Torsten.

Subject: solve command

From: Bruno Luong

Date: 25 Mar, 2009 12:10:03

Message: 12 of 21

Torsten Hennig <Torsten.Hennig@umsicht.fhg.de> wrote in message <13802981.1237981373076.JavaMail.jakarta@nitrogen.mathforum.org>...
> >
> > Hi Torsen,
> >
> > Yes, the backslash actually produces the least-square
> > solution for overdetermined system (minimizing the
> > norm of the residual, on the image space), as with
> > pinv.
> >
> > However if the matrix has non-trivial kernel
> > (different {0}), then backslash selects a solution
> > that is usually not the minimum-norm solution
> > (minimize the norm on the source space, but sill
> > least-square solution). This is the main difference
> > between pinv.
> >
> > Hope it is clear,
> >
> > Bruno
>
> Hi Bruno,
>
> cited from MATLAB documentation for square matrices:
>
> http://www.mathworks.com/access/helpdesk/help/techdoc/index.html?/access/helpdesk/help/techdoc/math/f4-983672.html&http://www.google.de/search?hl=de&q=matlab+%26+linear+equations&meta=
>
> "If A is singular, the solution to Ax = b either does not exist, or is not unique. The backslash operator, A\b, issues a warning if A is nearly singular and raises an error condition if it detects exact singularity."
>
> So in the case A is singular, a solution with the
> backslash operator (either exact or in the least-squares sense) can not be obtained ?
>

Hi Torsen,

No, "\" succeeds, even invert on degenerated matrix. Please see example below:

% Column 1 and 3 are dependent,
% rank A is two
A= [ 1 0 1;
       0 1 0;
       0 0 0;
       0 0 0 ];
 
b=(1:4).';

x1=A\b % [1 2 0]'
x2=pinv(A)*b %[0.5 2 0.5]'

% The linear maps the solutions to two equal results
% i.e., x = argmin |A*x - b| for both x1 and x2
y1=A*x1 [1 2 0 0]'
y2=A*x2 % idem as y1

% x2 however is selected is minimal norm, they differ by something in <null(A)>
norm(x1) % 2.2361
norm(x2) % 2.1213

% Bruno

Subject: solve command

From: Shane

Date: 25 Mar, 2009 12:10:04

Message: 13 of 21

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <gqd172$fp1$1@fred.mathworks.com>...
> Torsten Hennig <Torsten.Hennig@umsicht.fhg.de> wrote in message <29391649.1237975774607.JavaMail.jakarta@nitrogen.mathforum.org>...
>
> >
> > As I read in the MATLAB documentation, the backslash
> > operation does not seem to produce a least-squares
> > solution in the case of square systems if the coefficient
> > matrix is singular.
> >
> > Instead, you can try
> > x = pinv(A*R)*b
> >
> > Best wishes
> > Torsten.
>
> Hi Torsen,
>
> Yes, the backslash actually produces the least-square solution for overdetermined system (minimizing the norm of the residual, on the image space), as with pinv.
>
> However if the matrix has non-trivial kernel (different {0}), then backslash selects a solution that is usually not the minimum-norm solution (minimize the norm on the source space, but sill least-square solution). This is the main difference between pinv.
>
> Hope it is clear,
>
> Bruno


Thanks for the clearings.
I tried to built the A Matrix in another way. So the new equation is A*x=B.
But when I try to solve this problem with x=A\B or x=inv(A)*B, then the results is not quite correct. I guess it must be a rounding error or something like that.
Is it possible solve this problem in another way, e.g. an iteration method??

Shane

Subject: solve command

From: Bruno Luong

Date: 25 Mar, 2009 12:26:01

Message: 14 of 21

"Shane " <black.gentz@hotmail.de> wrote in message <gqd6us$7m9$1@fred.mathworks.com>...

>
>
> Thanks for the clearings.
> I tried to built the A Matrix in another way. So the new equation is A*x=B.
> But when I try to solve this problem with x=A\B or x=inv(A)*B, then the results is not quite correct.

Why you think it is not correct? Usually Matlab always gives a (numerically) consistent result: least-square, and least-norm when using PINV.

It might not what you are expecting, but you have not told us why.

>I guess it must be a rounding error or something like that.
> Is it possible solve this problem in another way, e.g. an iteration method??
>

You could provide a tolerance in PINV, that cut the rank, or using the iterative method and let it not totally converging.

But again, keep in mind that you are dealing with ill-posed linear system, and there are an infinity number of solutions. Matlab pick a result that you don't like, but because you had not tell it what you really want.

Bruno

Subject: solve command

From: Shane

Date: 25 Mar, 2009 14:14:02

Message: 15 of 21

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <gqd7sp$9t2$1@fred.mathworks.com>...
> "Shane " <black.gentz@hotmail.de> wrote in message <gqd6us$7m9$1@fred.mathworks.com>...
>
> >
> >
> > Thanks for the clearings.
> > I tried to built the A Matrix in another way. So the new equation is A*x=B.
> > But when I try to solve this problem with x=A\B or x=inv(A)*B, then the results is not quite correct.
>
> Why you think it is not correct? Usually Matlab always gives a (numerically) consistent result: least-square, and least-norm when using PINV.
>
> It might not what you are expecting, but you have not told us why.
>
> >I guess it must be a rounding error or something like that.
> > Is it possible solve this problem in another way, e.g. an iteration method??
> >
>
> You could provide a tolerance in PINV, that cut the rank, or using the iterative method and let it not totally converging.
>
> But again, keep in mind that you are dealing with ill-posed linear system, and there are an infinity number of solutions. Matlab pick a result that you don't like, but because you had not tell it what you really want.
>
> Bruno


The right solution of the my problem is:
x=(149,344; 149,004; 156,321; 157,021; 156,568; 155,871; 155,049; 153,96; 151,631; 142,069].

But with the command x=b'/A I get for x:
x=[149,465; 149,995; 154,4257; 154,8244; 154,5465; 154,1209; 153,5739; 152,5583; 148,8012; 127,751]

and with the command x=inv(A)*b or x=pinv(A)*b the result is:
x=[149.292; 149.852; 154.273; 154.670; 154.386; 153.916; 153.086; 150.276; 135.100; 143.012]

so you can see that there is a difference between each solution. My Question is if the is anothe method so solve the equation. I guess the problem is the A-Matrix, because the condition is not really good, cond(A)=49,0233.

Subject: solve command

From: Bruno Luong

Date: 25 Mar, 2009 14:40:19

Message: 16 of 21

"Shane " <black.gentz@hotmail.de> wrote in message <gqde7a$lr6$1@fred.mathworks.com>...
> "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <gqd7sp$9t2$1@fred.mathworks.com>...
> > "Shane " <black.gentz@hotmail.de> wrote in message <gqd6us$7m9$1@fred.mathworks.com>...
> >
> > >
> > >
> > > Thanks for the clearings.
> > > I tried to built the A Matrix in another way. So the new equation is A*x=B.
> > > But when I try to solve this problem with x=A\B or x=inv(A)*B, then the results is not quite correct.
> >
> > Why you think it is not correct? Usually Matlab always gives a (numerically) consistent result: least-square, and least-norm when using PINV.
> >
> > It might not what you are expecting, but you have not told us why.
> >
> > >I guess it must be a rounding error or something like that.
> > > Is it possible solve this problem in another way, e.g. an iteration method??
> > >
> >
> > You could provide a tolerance in PINV, that cut the rank, or using the iterative method and let it not totally converging.
> >
> > But again, keep in mind that you are dealing with ill-posed linear system, and there are an infinity number of solutions. Matlab pick a result that you don't like, but because you had not tell it what you really want.
> >
> > Bruno
>
>
> The right solution of the my problem is:
> x=(149,344; 149,004; 156,321; 157,021; 156,568; 155,871; 155,049; 153,96; 151,631; 142,069].

And what indicated this is "more" right?
>
> But with the command x=b'/A I get for x:
> x=[149,465; 149,995; 154,4257; 154,8244; 154,5465; 154,1209; 153,5739; 152,5583; 148,8012; 127,751]
>
> and with the command x=inv(A)*b or x=pinv(A)*b the result is:
> x=[149.292; 149.852; 154.273; 154.670; 154.386; 153.916; 153.086; 150.276; 135.100; 143.012]

I fail to see why they are not right? Both solutions satisfy A*x = b, and that's the only target of a linear inversion.

>
> so you can see that there is a difference between each solution.

Yes, and I'm not surprised.


>My Question is if the is anothe method so solve the equation. I guess the problem is the A-Matrix, because the condition is not really good, cond(A)=49,0233.

You can even take any combination of the three above solutions
x = c1*x1 + c2*x2 + c3*x3, with sum ci = 1

And you still have
A*x = b.

Allow me to repeat one more time: there are an infinity of solutions. If you cannot clearly *formulate* what solution is right for you, you might spend a lot of time chasing forever the algorithm that gives the "right" solution.

Second alternative: you just have to accept that the solutions given by an algorithm can be also "right".

Bruno

Subject: solve command

From: Shane

Date: 26 Mar, 2009 07:02:02

Message: 17 of 21

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <gqdfoj$es8$1@fred.mathworks.com>...
> "Shane " <black.gentz@hotmail.de> wrote in message <gqde7a$lr6$1@fred.mathworks.com>...
> > "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <gqd7sp$9t2$1@fred.mathworks.com>...
> > > "Shane " <black.gentz@hotmail.de> wrote in message <gqd6us$7m9$1@fred.mathworks.com>...
> > >
> > > >
> > > >
> > > > Thanks for the clearings.
> > > > I tried to built the A Matrix in another way. So the new equation is A*x=B.
> > > > But when I try to solve this problem with x=A\B or x=inv(A)*B, then the results is not quite correct.
> > >
> > > Why you think it is not correct? Usually Matlab always gives a (numerically) consistent result: least-square, and least-norm when using PINV.
> > >
> > > It might not what you are expecting, but you have not told us why.
> > >
> > > >I guess it must be a rounding error or something like that.
> > > > Is it possible solve this problem in another way, e.g. an iteration method??
> > > >
> > >
> > > You could provide a tolerance in PINV, that cut the rank, or using the iterative method and let it not totally converging.
> > >
> > > But again, keep in mind that you are dealing with ill-posed linear system, and there are an infinity number of solutions. Matlab pick a result that you don't like, but because you had not tell it what you really want.
> > >
> > > Bruno
> >
> >
> > The right solution of the my problem is:
> > x=(149,344; 149,004; 156,321; 157,021; 156,568; 155,871; 155,049; 153,96; 151,631; 142,069].
>
> And what indicated this is "more" right?
> >
> > But with the command x=b'/A I get for x:
> > x=[149,465; 149,995; 154,4257; 154,8244; 154,5465; 154,1209; 153,5739; 152,5583; 148,8012; 127,751]
> >
> > and with the command x=inv(A)*b or x=pinv(A)*b the result is:
> > x=[149.292; 149.852; 154.273; 154.670; 154.386; 153.916; 153.086; 150.276; 135.100; 143.012]
>
> I fail to see why they are not right? Both solutions satisfy A*x = b, and that's the only target of a linear inversion.
>
> >
> > so you can see that there is a difference between each solution.
>
> Yes, and I'm not surprised.
>
>
> >My Question is if the is anothe method so solve the equation. I guess the problem is the A-Matrix, because the condition is not really good, cond(A)=49,0233.
>
> You can even take any combination of the three above solutions
> x = c1*x1 + c2*x2 + c3*x3, with sum ci = 1
>
> And you still have
> A*x = b.
>
> Allow me to repeat one more time: there are an infinity of solutions. If you cannot clearly *formulate* what solution is right for you, you might spend a lot of time chasing forever the algorithm that gives the "right" solution.
>
> Second alternative: you just have to accept that the solutions given by an algorithm can be also "right".
>
> Bruno


Hi Bruno,
now I clearly understand what you mean. Thats the point, how can I say to Matlab, which solution he had to pick or rather what kind of options I have to say which solution is right for me??

Subject: solve command

From: Torsten Hennig

Date: 26 Mar, 2009 07:33:29

Message: 18 of 21

> "Bruno Luong" <b.luong@fogale.findmycountry> wrote in
> message <gqdfoj$es8$1@fred.mathworks.com>...
> > "Shane " <black.gentz@hotmail.de> wrote in message
> <gqde7a$lr6$1@fred.mathworks.com>...
> > > "Bruno Luong" <b.luong@fogale.findmycountry>
> wrote in message <gqd7sp$9t2$1@fred.mathworks.com>...
> > > > "Shane " <black.gentz@hotmail.de> wrote in
> message <gqd6us$7m9$1@fred.mathworks.com>...
> > > >
> > > > >
> > > > >
> > > > > Thanks for the clearings.
> > > > > I tried to built the A Matrix in another way.
> So the new equation is A*x=B.
> > > > > But when I try to solve this problem with
> x=A\B or x=inv(A)*B, then the results is not quite
> correct.
> > > >
> > > > Why you think it is not correct? Usually Matlab
> always gives a (numerically) consistent result:
> least-square, and least-norm when using PINV.
> > > >
> > > > It might not what you are expecting, but you
> have not told us why.
> > > >
> > > > >I guess it must be a rounding error or
> something like that.
> > > > > Is it possible solve this problem in another
> way, e.g. an iteration method??
> > > > >
> > > >
> > > > You could provide a tolerance in PINV, that cut
> the rank, or using the iterative method and let it
> not totally converging.
> > > >
> > > > But again, keep in mind that you are dealing
> with ill-posed linear system, and there are an
> infinity number of solutions. Matlab pick a result
> that you don't like, but because you had not tell it
> what you really want.
> > > >
> > > > Bruno
> > >
> > >
> > > The right solution of the my problem is:
> > > x=(149,344; 149,004; 156,321; 157,021; 156,568;
> 155,871; 155,049; 153,96; 151,631; 142,069].
> >
> > And what indicated this is "more" right?
> > >
> > > But with the command x=b'/A I get for x:
> > > x=[149,465; 149,995; 154,4257; 154,8244;
> 154,5465; 154,1209; 153,5739; 152,5583; 148,8012;
> 127,751]
> > >
> > > and with the command x=inv(A)*b or x=pinv(A)*b
> the result is:
> > > x=[149.292; 149.852; 154.273; 154.670; 154.386;
> 153.916; 153.086; 150.276; 135.100; 143.012]
> >
> > I fail to see why they are not right? Both
> solutions satisfy A*x = b, and that's the only target
> of a linear inversion.
> >
> > >
> > > so you can see that there is a difference between
> each solution.
> >
> > Yes, and I'm not surprised.
> >
> >
> > >My Question is if the is anothe method so solve
> the equation. I guess the problem is the A-Matrix,
> because the condition is not really good,
> cond(A)=49,0233.
> >
> > You can even take any combination of the three
> above solutions
> > x = c1*x1 + c2*x2 + c3*x3, with sum ci = 1
> >
> > And you still have
> > A*x = b.
> >
> > Allow me to repeat one more time: there are an
> infinity of solutions. If you cannot clearly
> *formulate* what solution is right for you, you
> u might spend a lot of time chasing forever the
> algorithm that gives the "right" solution.
> >
> > Second alternative: you just have to accept that
> the solutions given by an algorithm can be also
> "right".
> >
> > Bruno
>
>
> Hi Bruno,
> now I clearly understand what you mean. Thats the
> point, how can I say to Matlab, which solution he had
> to pick or rather what kind of options I have to say
> which solution is right for me??

First you have to formulate the criterium (criteria)
for a solution to be false or right for you.
Then we can think about a way to tell MATLAB which
solution it should select.

Best wishes
Torsten.

Subject: solve command

From: Bruno Luong

Date: 26 Mar, 2009 07:55:03

Message: 19 of 21


> Hi Bruno,
> now I clearly understand what you mean. Thats the point, how can I say to Matlab, which solution he had to pick or rather what kind of options I have to say which solution is right for me??

Shane I invite you to medidate about this example:
A = [1 0 1
     0 1 1]
xright = [-1 1 3]'
b=A*xright

% Try to find xright:
x1 = A\b
x2 = pinv(A)*b

%%%%

Mr S.: x1 and x2 are not right, because it is not x, which I want
Mr Matlab: why? A*x1 = b and A*x2=b, they are both fine
Mr S: yes but I want x, not x1 and x2
Mr Matlab: Tell me more, how should I select x if you only gives me A and b?
Mr S: Because... <- you need to fill the rest of the story here

Bruno

Subject: solve command

From: Shane

Date: 26 Mar, 2009 08:32:01

Message: 20 of 21


> Shane I invite you to medidate about this example:
> A = [1 0 1
> 0 1 1]
> xright = [-1 1 3]'
> b=A*xright
>
> % Try to find xright:
> x1 = A\b
> x2 = pinv(A)*b
>
> %%%%
>
> Mr S.: x1 and x2 are not right, because it is not x, which I want
> Mr Matlab: why? A*x1 = b and A*x2=b, they are both fine
> Mr S: yes but I want x, not x1 and x2
> Mr Matlab: Tell me more, how should I select x if you only gives me A and b?
> Mr S: Because... <- you need to fill the rest of the story here
>
> Bruno

Yes, I understand both of you now. I need more terms or conditions for x to find the right solution. Give me please more time to find more conditions for x. I hope you will help me then to "tell" Matlab these sondiotions.
Thanks a lot.

Shanne

Subject: solve command

From: Shane

Date: 1 Apr, 2009 09:12:01

Message: 21 of 21

"Shane " <black.gentz@hotmail.de> wrote in message <gqfei1$d4r$1@fred.mathworks.com>...
>
> > Shane I invite you to medidate about this example:
> > A = [1 0 1
> > 0 1 1]
> > xright = [-1 1 3]'
> > b=A*xright
> >
> > % Try to find xright:
> > x1 = A\b
> > x2 = pinv(A)*b
> >
> > %%%%
> >
> > Mr S.: x1 and x2 are not right, because it is not x, which I want
> > Mr Matlab: why? A*x1 = b and A*x2=b, they are both fine
> > Mr S: yes but I want x, not x1 and x2
> > Mr Matlab: Tell me more, how should I select x if you only gives me A and b?
> > Mr S: Because... <- you need to fill the rest of the story here
> >
> > Bruno
>
> Yes, I understand both of you now. I need more terms or conditions for x to find the right solution. Give me please more time to find more conditions for x. I hope you will help me then to "tell" Matlab these sondiotions.
> Thanks a lot.
>
> Shanne

hey Guys,
I find now the right solution for my problems.
Thanks a lot for your helps and suggestions.

Shane

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us