<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239859</link>
    <title>MATLAB Central Newsreader - inv(rand(6,6,2)) question</title>
    <description>Feed for thread: inv(rand(6,6,2)) question</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Mon, 24 Nov 2008 20:22:02 -0500</pubDate>
      <title>inv(rand(6,6,2)) question</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239859#612999</link>
      <author>Hydroman S</author>
      <description>The question is some what related to my earlier post about matix division: &lt;br&gt;
&lt;br&gt;
How come x=inv(rand(3,3,2)); &lt;br&gt;
gives this error:&lt;br&gt;
&lt;br&gt;
&amp;gt;&amp;gt; x=inv(rand(6,6,2))&lt;br&gt;
??? Error using ==&amp;gt; inv&lt;br&gt;
Input arguments must be 2-D.&lt;br&gt;
&lt;br&gt;
shouldn't each of the 2 matrcies in  rand(6,6,2) give us a separate inverse? </description>
    </item>
    <item>
      <pubDate>Mon, 24 Nov 2008 20:28:02 -0500</pubDate>
      <title>Re: inv(rand(6,6,2)) question</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239859#613000</link>
      <author>Bruno Luong</author>
      <description>&quot;Hydroman S&quot; &amp;lt;amirgsalem@gmail.com&amp;gt; wrote in message &amp;lt;ggf2da$898$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; shouldn't each of the 2 matrcies in  rand(6,6,2) give us a separate inverse? &lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
No.&lt;br&gt;
&lt;br&gt;
Bruno</description>
    </item>
    <item>
      <pubDate>Mon, 24 Nov 2008 20:37:01 -0500</pubDate>
      <title>Re: inv(rand(6,6,2)) question</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239859#613004</link>
      <author>Hydroman S</author>
      <description>&quot;Bruno Luong&quot; &amp;lt;b.luong@fogale.findmycountry&amp;gt; wrote in message &amp;lt;ggf2oi$dfo$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Hydroman S&quot; &amp;lt;amirgsalem@gmail.com&amp;gt; wrote in message &amp;lt;ggf2da$898$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; shouldn't each of the 2 matrcies in  rand(6,6,2) give us a separate inverse? &lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; No.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Bruno&lt;br&gt;
&lt;br&gt;
fine, now if I put it in a loop, I would think that it would work, but it also doesn't:&lt;br&gt;
&lt;br&gt;
for i=1:6&lt;br&gt;
x=inv(rand(3,3,i)); &lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
??? Error using ==&amp;gt; inv&lt;br&gt;
Input arguments must be 2-D.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
I also applied squeeze, but it does not work as well.  My problem is why? since inside the loop, rand(3,3,1) is gives a square matrix&lt;br&gt;
&lt;br&gt;
for i=1:2&lt;br&gt;
x=squeeze(inv(rand(3,3,i))); &lt;br&gt;
end</description>
    </item>
    <item>
      <pubDate>Mon, 24 Nov 2008 21:07:02 -0500</pubDate>
      <title>Re: inv(rand(6,6,2)) question</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239859#613007</link>
      <author>alistair templeton</author>
      <description>&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I also applied squeeze, but it does not work as well.  My problem is why? since inside the loop, rand(3,3,1) is gives a square matrix&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; for i=1:2&lt;br&gt;
&amp;gt; x=squeeze(inv(rand(3,3,i))); &lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
what about when i=2?</description>
    </item>
    <item>
      <pubDate>Mon, 24 Nov 2008 21:16:03 -0500</pubDate>
      <title>Re: inv(rand(6,6,2)) question</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239859#613009</link>
      <author>Bruno Luong</author>
      <description>&quot;Hydroman S&quot; &amp;lt;amirgsalem@gmail.com&amp;gt; wrote in message &amp;lt;ggf39d$mlm$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; fine, now if I put it in a loop, I would think that it would work, but it also doesn't:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; for i=1:6&lt;br&gt;
&amp;gt; x=inv(rand(3,3,i)); &lt;br&gt;
&amp;gt; end&lt;br&gt;
&lt;br&gt;
Your loop cannot work&lt;br&gt;
&lt;br&gt;
let's decompose, when i=2&lt;br&gt;
&lt;br&gt;
rand(3,3,i) returns rand(3,3,2).&lt;br&gt;
&lt;br&gt;
Similar issue occurs for i=3,4,5,6.&lt;br&gt;
&lt;br&gt;
It's still a three dimensional array, and MATLAB INV does like it.&lt;br&gt;
&lt;br&gt;
What you need is create the 3D array BEFORE the for-loop, then loop over the last indice. You must put a squeeze somewhere to reduce the dimension.&lt;br&gt;
&lt;br&gt;
I let you figure out how to do that.&lt;br&gt;
&lt;br&gt;
Bruno</description>
    </item>
    <item>
      <pubDate>Mon, 24 Nov 2008 21:23:02 -0500</pubDate>
      <title>Re: inv(rand(6,6,2)) question</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239859#613012</link>
      <author>Hydroman S</author>
      <description>&quot;Alistair Templeton&quot; &amp;lt;bigalt2000@yahoo.com&amp;gt; wrote in message &amp;lt;ggf51m$pdq$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; I also applied squeeze, but it does not work as well.  My problem is why? since inside the loop, rand(3,3,1) is gives a square matrix&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; for i=1:2&lt;br&gt;
&amp;gt; &amp;gt; x=squeeze(inv(rand(3,3,i))); &lt;br&gt;
&amp;gt; &amp;gt; end&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; what about when i=2?&lt;br&gt;
&lt;br&gt;
Point well taken. sorry I wasn't thinking clearly. So what would be the proper way to find the inv in this case? </description>
    </item>
    <item>
      <pubDate>Mon, 24 Nov 2008 21:25:03 -0500</pubDate>
      <title>Re: inv(rand(6,6,2)) question</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239859#613013</link>
      <author>Hydroman S</author>
      <description>&quot;Bruno Luong&quot; &amp;lt;b.luong@fogale.findmycountry&amp;gt; wrote in message &amp;lt;ggf5ij$61d$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Hydroman S&quot; &amp;lt;amirgsalem@gmail.com&amp;gt; wrote in message &amp;lt;ggf39d$mlm$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; fine, now if I put it in a loop, I would think that it would work, but it also doesn't:&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; for i=1:6&lt;br&gt;
&amp;gt; &amp;gt; x=inv(rand(3,3,i)); &lt;br&gt;
&amp;gt; &amp;gt; end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Your loop cannot work&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; let's decompose, when i=2&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; rand(3,3,i) returns rand(3,3,2).&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Similar issue occurs for i=3,4,5,6.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; It's still a three dimensional array, and MATLAB INV does like it.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; What you need is create the 3D array BEFORE the for-loop, then loop over the last indice. You must put a squeeze somewhere to reduce the dimension.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I let you figure out how to do that.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Bruno&lt;br&gt;
&lt;br&gt;
Thanks Bruno, let me give it shot...</description>
    </item>
    <item>
      <pubDate>Mon, 24 Nov 2008 21:29:01 -0500</pubDate>
      <title>Re: inv(rand(6,6,2)) question</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239859#613014</link>
      <author>chaintzean </author>
      <description>&quot;Hydroman S&quot; &amp;lt;amirgsalem@gmail.com&amp;gt; wrote in message &amp;lt;ggf39d$mlm$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Bruno Luong&quot; &amp;lt;b.luong@fogale.findmycountry&amp;gt; wrote in message &amp;lt;ggf2oi$dfo$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; &quot;Hydroman S&quot; &amp;lt;amirgsalem@gmail.com&amp;gt; wrote in message &amp;lt;ggf2da$898$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; shouldn't each of the 2 matrcies in  rand(6,6,2) give us a separate inverse? &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; No.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Bruno&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; fine, now if I put it in a loop, I would think that it would work, but it also doesn't:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; for i=1:6&lt;br&gt;
&amp;gt; x=inv(rand(3,3,i)); &lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; ??? Error using ==&amp;gt; inv&lt;br&gt;
&amp;gt; Input arguments must be 2-D.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I also applied squeeze, but it does not work as well.  My problem is why? since inside the loop, rand(3,3,1) is gives a square matrix&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; for i=1:2&lt;br&gt;
&amp;gt; x=squeeze(inv(rand(3,3,i))); &lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
It seems like you don't understand how rand() works.  If what you really need to do is to inverse sub-matrices of a random 3-dimensional matrix (which I doubt), then looping on it would have to be done that way:&lt;br&gt;
&lt;br&gt;
X = rand(6,6,2);&lt;br&gt;
&lt;br&gt;
for i=1:2&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;X_inv(:,:,i) = inv(squeeze(X(:,:,i)));&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
rand(3,3,i) generates a 3x3x(i) array which cannot be inverted (except for i=1, of course).  Also, why would you squeeze outside of the inv call?  By the way, you don't even need to squeeze in my example above, I just wanted to illustrate proper use.</description>
    </item>
    <item>
      <pubDate>Mon, 24 Nov 2008 21:36:57 -0500</pubDate>
      <title>Re: inv(rand(6,6,2)) question</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239859#613020</link>
      <author>Doug Schwarz</author>
      <description>In article &amp;lt;ggf39d$mlm$1@fred.mathworks.com&amp;gt;,&lt;br&gt;
&amp;nbsp;&quot;Hydroman S&quot; &amp;lt;amirgsalem@gmail.com&amp;gt; wrote:&lt;br&gt;
&lt;br&gt;
&amp;gt; &quot;Bruno Luong&quot; &amp;lt;b.luong@fogale.findmycountry&amp;gt; wrote in message &lt;br&gt;
&amp;gt; &amp;lt;ggf2oi$dfo$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; &quot;Hydroman S&quot; &amp;lt;amirgsalem@gmail.com&amp;gt; wrote in message &lt;br&gt;
&amp;gt; &amp;gt; &amp;lt;ggf2da$898$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; shouldn't each of the 2 matrcies in  rand(6,6,2) give us a separate &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; inverse? &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; No.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Bruno&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; fine, now if I put it in a loop, I would think that it would work, but it &lt;br&gt;
&amp;gt; also doesn't:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; for i=1:6&lt;br&gt;
&amp;gt; x=inv(rand(3,3,i)); &lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; ??? Error using ==&amp;gt; inv&lt;br&gt;
&amp;gt; Input arguments must be 2-D.&lt;br&gt;
&lt;br&gt;
Think about what you are doing.  The first time through the loop you &lt;br&gt;
generate a 3x3x1 matrix and that works.  The second time through the &lt;br&gt;
loop you generate a 3x3x2 matrix and that doesn't work.&lt;br&gt;
&lt;br&gt;
What you want to do is generate the matrix once and then pick each plane &lt;br&gt;
in turn:&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;A = rand(6,6,n);&lt;br&gt;
&amp;nbsp;&amp;nbsp;for i = 1:n&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;B(:,:,i) = inv(A(:,:,i));&lt;br&gt;
&amp;nbsp;&amp;nbsp;end&lt;br&gt;
&lt;br&gt;
(Of course, you probably shouldn't be using inverses in the first place.)&lt;br&gt;
&lt;br&gt;
-- &lt;br&gt;
Doug Schwarz&lt;br&gt;
dmschwarz&amp;ieee,org&lt;br&gt;
Make obvious changes to get real email address.</description>
    </item>
    <item>
      <pubDate>Mon, 24 Nov 2008 21:42:02 -0500</pubDate>
      <title>Re: inv(rand(6,6,2)) question</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239859#613023</link>
      <author>Hydroman S</author>
      <description>&quot;chaintzean &quot; &amp;lt;chaintzean@hotmail.com&amp;gt; wrote in message &amp;lt;ggf6at$ino$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Hydroman S&quot; &amp;lt;amirgsalem@gmail.com&amp;gt; wrote in message &amp;lt;ggf39d$mlm$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; &quot;Bruno Luong&quot; &amp;lt;b.luong@fogale.findmycountry&amp;gt; wrote in message &amp;lt;ggf2oi$dfo$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &quot;Hydroman S&quot; &amp;lt;amirgsalem@gmail.com&amp;gt; wrote in message &amp;lt;ggf2da$898$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; shouldn't each of the 2 matrcies in  rand(6,6,2) give us a separate inverse? &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; No.&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; Bruno&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; fine, now if I put it in a loop, I would think that it would work, but it also doesn't:&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; for i=1:6&lt;br&gt;
&amp;gt; &amp;gt; x=inv(rand(3,3,i)); &lt;br&gt;
&amp;gt; &amp;gt; end&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; ??? Error using ==&amp;gt; inv&lt;br&gt;
&amp;gt; &amp;gt; Input arguments must be 2-D.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; I also applied squeeze, but it does not work as well.  My problem is why? since inside the loop, rand(3,3,1) is gives a square matrix&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; for i=1:2&lt;br&gt;
&amp;gt; &amp;gt; x=squeeze(inv(rand(3,3,i))); &lt;br&gt;
&amp;gt; &amp;gt; end&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; It seems like you don't understand how rand() works.  If what you really need to do is to inverse sub-matrices of a random 3-dimensional matrix (which I doubt), then looping on it would have to be done that way:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; X = rand(6,6,2);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; for i=1:2&lt;br&gt;
&amp;gt;     X_inv(:,:,i) = inv(squeeze(X(:,:,i)));&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; rand(3,3,i) generates a 3x3x(i) array which cannot be inverted (except for i=1, of course).  Also, why would you squeeze outside of the inv call?  By the way, you don't even need to squeeze in my example above, I just wanted to illustrate proper use.&lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
Thanks chaintzean this also answes my question. </description>
    </item>
  </channel>
</rss>

