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:
Again about inv function

Subject: Again about inv function

From: Peter Ganzo

Date: 26 Oct, 2010 15:11:03

Message: 1 of 7

Dear all,
I have a problem about how to use inv function

Here is my data:

A=[0,0290478678447601 -0,0141099913256855 -0,000769229870092528 0,000834888891356351 -0,000767833744239176 0,000447557353876793 -0,000341233167625316 0,000213594979723706 0,000405975161430466 -0,000347763223565095 -0,00607388361880634
-0,0141099913256855 0,0290281770724332 -0,0141102570779875 -0,000765746512551112 0,000839259102833237 -0,000765866696806914 0,000477892639136813 -0,000352414875015785 0,000191134961756833 0,000431471009695488 -0,000282781975670332
-0,000769229870092528 -0,0141102570779875 0,0290405944632981 -0,0141283489207921 -0,000739653617576184 0,000822134312336111 -0,000753946667740606 0,000464069879338386 -0,000347165016618071 0,000191210163393539 0,00439484543546254
0,000834888891356351 -0,000765746512551112 -0,0141283489207921 0,0290664671496478 -0,0141671403997143 -0,000714954802116445 0,000799958491511303 -0,000732003037417882 0,000459933876232131 -0,000351282627683021 -0,00334640849289780
-0,000767833744239176 0,000839259102833237 -0,000739653617576184 -0,0141671403997143 0,0291200633432482 -0,0142035255464521 -0,000697561651568423 0,000773784490655982 -0,000715379360351614 0,000453711674401027 0,00500862063732566
0,000447557353876793 -0,000765866696806914 0,000822134312336111 -0,000714954802116445 -0,0142035255464521 0,0291435500341477 -0,0142224502249874 -0,000677566047258281 0,000768360412858587 -0,000717555013319865 -0,00192100699517450
-0,000341233167625316 0,000477892639136813 -0,000753946667740606 0,000799958491511303 -0,000697561651568423 -0,0142224502249874 0,0291074829602388 -0,0142178936743960 -0,000637818512866281 0,000728832732028223 -0,00658032116618745
0,000213594979723706 -0,000352414875015785 0,000464069879338386 -0,000732003037417882 0,000773784490655982 -0,000677566047258281 -0,0142178936743960 0,0291161819455991 -0,0142367601462918 -0,000623044326656091 -0,00835441975655993
0,000405975161430466 0,000191134961756833 -0,000347165016618071 0,000459933876232131 -0,000715379360351614 0,000768360412858587 -0,000637818512866281 -0,0142367601462918 0,0290930457701177 -0,0142077988602857 0,000307385394330950
-0,000347763223565095 0,000431471009695488 0,000191210163393539 -0,000351282627683021 0,000453711674401027 -0,000717555013319865 0,000728832732028223 -0,000623044326656091 -0,0142077988602857 0,0290600392611528 -0,00729057488009133
-0,00607388361880634 -0,000282781975670332 0,00439484543546254 -0,00334640849289780 0,00500862063732566 -0,00192100699517450 -0,00658032116618745 -0,00835441975655993 0,000307385394330950 -0,00729057488009133 2187];

b=7,25152487284537e-06;

Using inv I can make var_cov=b*inv(A)
but if I want to use more accurate / or \ how do I have to procede?

Thanks a lot in advance to everyone

Peter

Subject: Again about inv function

From: Miroslav Balda

Date: 26 Oct, 2010 16:50:07

Message: 2 of 7

"Peter Ganzo " <mgnotar@gmail.com> wrote in message <ia6r27$juh$1@fred.mathworks.com>...
> Dear all,
> I have a problem about how to use inv function
>
> Here is my data:
>
> A=[0,0290478678447601 -0,0141099913256855 -0,000769229870092528 0,000834888891356351 -0,000767833744239176 0,000447557353876793 -0,000341233167625316 0,000213594979723706 0,000405975161430466 -0,000347763223565095 -0,00607388361880634
> -0,0141099913256855 0,0290281770724332 -0,0141102570779875 -0,000765746512551112 0,000839259102833237 -0,000765866696806914 0,000477892639136813 -0,000352414875015785 0,000191134961756833 0,000431471009695488 -0,000282781975670332
> -0,000769229870092528 -0,0141102570779875 0,0290405944632981 -0,0141283489207921 -0,000739653617576184 0,000822134312336111 -0,000753946667740606 0,000464069879338386 -0,000347165016618071 0,000191210163393539 0,00439484543546254
> 0,000834888891356351 -0,000765746512551112 -0,0141283489207921 0,0290664671496478 -0,0141671403997143 -0,000714954802116445 0,000799958491511303 -0,000732003037417882 0,000459933876232131 -0,000351282627683021 -0,00334640849289780
> -0,000767833744239176 0,000839259102833237 -0,000739653617576184 -0,0141671403997143 0,0291200633432482 -0,0142035255464521 -0,000697561651568423 0,000773784490655982 -0,000715379360351614 0,000453711674401027 0,00500862063732566
> 0,000447557353876793 -0,000765866696806914 0,000822134312336111 -0,000714954802116445 -0,0142035255464521 0,0291435500341477 -0,0142224502249874 -0,000677566047258281 0,000768360412858587 -0,000717555013319865 -0,00192100699517450
> -0,000341233167625316 0,000477892639136813 -0,000753946667740606 0,000799958491511303 -0,000697561651568423 -0,0142224502249874 0,0291074829602388 -0,0142178936743960 -0,000637818512866281 0,000728832732028223 -0,00658032116618745
> 0,000213594979723706 -0,000352414875015785 0,000464069879338386 -0,000732003037417882 0,000773784490655982 -0,000677566047258281 -0,0142178936743960 0,0291161819455991 -0,0142367601462918 -0,000623044326656091 -0,00835441975655993
> 0,000405975161430466 0,000191134961756833 -0,000347165016618071 0,000459933876232131 -0,000715379360351614 0,000768360412858587 -0,000637818512866281 -0,0142367601462918 0,0290930457701177 -0,0142077988602857 0,000307385394330950
> -0,000347763223565095 0,000431471009695488 0,000191210163393539 -0,000351282627683021 0,000453711674401027 -0,000717555013319865 0,000728832732028223 -0,000623044326656091 -0,0142077988602857 0,0290600392611528 -0,00729057488009133
> -0,00607388361880634 -0,000282781975670332 0,00439484543546254 -0,00334640849289780 0,00500862063732566 -0,00192100699517450 -0,00658032116618745 -0,00835441975655993 0,000307385394330950 -0,00729057488009133 2187];
>
> b=7,25152487284537e-06;
>
> Using inv I can make var_cov=b*inv(A)
> but if I want to use more accurate / or \ how do I have to procede?
>
> Thanks a lot in advance to everyone
>
> Peter

Hi Peter,

Remember that if you wish to get good answer, the formulation of your question should also be good. I am afraid that your question is not good. Before you ask, you have to formulate your problem. Instead of that you wrote a solution
      var_cov = b*inv(A).
It means that var_cov would be a solution of the equation
      var_cov*A =b,
what is due to given sizes of the matrix A and the scalar b impossible.

A hint: formulate your problem and not a solution (which is wrong).

Mira

Subject: Again about inv function

From: Bruno Luong

Date: 26 Oct, 2010 17:20:07

Message: 3 of 7


> Hi Peter,
>
> Remember that if you wish to get good answer, the formulation of your question should also be good. I am afraid that your question is not good. Before you ask, you have to formulate your problem. Instead of that you wrote a solution
> var_cov = b*inv(A).

> It means that var_cov would be a solution of the equation
> var_cov*A =b,
> what is due to given sizes of the matrix A and the scalar b impossible.

Probably the correct equation is var_cov*A =b*eye(size(A)), and Peter's question makes perfectly sense.

Now I have heard and read that INV(A) is poorer than A\eye(size(A)) (not check myself). That begs the question: why TMW don't bother to implement INV(A) as A\eye(size(A)) instead of issuing the non-sense warning?

Bruno

Subject: Again about inv function

From: Peter Ganzo

Date: 26 Oct, 2010 19:48:06

Message: 4 of 7

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <ia72k6$ker$1@fred.mathworks.com>...
>
> > Hi Peter,
> >
> > Remember that if you wish to get good answer, the formulation of your question should also be good. I am afraid that your question is not good. Before you ask, you have to formulate your problem. Instead of that you wrote a solution
> > var_cov = b*inv(A).
>
> > It means that var_cov would be a solution of the equation
> > var_cov*A =b,
> > what is due to given sizes of the matrix A and the scalar b impossible.
>
> Probably the correct equation is var_cov*A =b*eye(size(A)), and Peter's question makes perfectly sense.
>
> Now I have heard and read that INV(A) is poorer than A\eye(size(A)) (not check myself). That begs the question: why TMW don't bother to implement INV(A) as A\eye(size(A)) instead of issuing the non-sense warning?
>
> Bruno

Thanks Miroslav and Bruno

Bruno your solution works well

var_cov = b*eye(size((A),1)) / A;

I am agreement on you question:
>why TMW don't bother to implement INV(A) as A\eye(size(A)) instead of issuing >the non-sense warning?

Cheers

Peter

Subject: Again about inv function

From: Steven_Lord

Date: 27 Oct, 2010 04:11:01

Message: 5 of 7



"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message
news:ia72k6$ker$1@fred.mathworks.com...
>
>> Hi Peter,
>>
>> Remember that if you wish to get good answer, the formulation of your
>> question should also be good. I am afraid that your question is not good.
>> Before you ask, you have to formulate your problem. Instead of that you
>> wrote a solution var_cov = b*inv(A).
>
>> It means that var_cov would be a solution of the equation
>> var_cov*A =b,
>> what is due to given sizes of the matrix A and the scalar b impossible.
>
> Probably the correct equation is var_cov*A =b*eye(size(A)), and Peter's
> question makes perfectly sense.
>
> Now I have heard and read that INV(A) is poorer than A\eye(size(A)) (not
> check myself). That begs the question: why TMW don't bother to implement
> INV(A) as A\eye(size(A)) instead of issuing the non-sense warning?

Because constructing an identity matrix the same size as the input matrix
would dramatically increase the memory consumption of INV. This could lead
to INV failing with an out-of-memory error if you called it on a moderately
large matrix.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Again about inv function

From: Bruno Luong

Date: 27 Oct, 2010 05:09:04

Message: 6 of 7

"Steven_Lord" <slord@mathworks.com> wrote in message <ia88ol$se0$1@fred.mathworks.com>...

>
> Because constructing an identity matrix the same size as the input matrix
> would dramatically increase the memory consumption of INV. This could lead
> to INV failing with an out-of-memory error if you called it on a moderately
> large matrix.

speye?

Bruno

Subject: Again about inv function

From: Bruno Luong

Date: 27 Oct, 2010 05:32:04

Message: 7 of 7

Allow me to elaborate more, here is what I observe, the MLINT message is on the first method "INV(A) is slow and inaccurate. Use A\b for INV(A)*B":

A=rand(3);
c=rand(3,10000);

%% METHOD 1: TAGGED AS BAD
tic
B=inv(A)*c;
toc

%% METHOD 2: MLINT SUGGESTION
tic
B=A\c;
toc

%% METHOD 3
tic
B=A\speye(size(A));
B=B*c;
toc

What I observe is Method 1 & 3 is faster than 2 (two to three times). So I conclude that method 1 with INV() must be "less accurate" according to MLINT. Method 3 is not warned by MLINT. So why TMW prefers to issue warning on Method 1 rather than implement INV(A) as A\speye(size(A))?

Bruno

Tags for this Thread

No tags are associated with 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