From: Matt J on 23 Jul 2010 16:42 "Stefan " <aidematlab(a)yahoo.ca> wrote in message <i2csjm$b49$1(a)fred.mathworks.com>... > You are both right, compute expm(B) outside the loop first. However, I need all the values of V. -a<= x1,x2,x3,x4 <=a, where a can be any integer. ============= I'm willing to lay odds that you don't need this and that it would be advisable for you to explain the bigger picture of what you're trying to do. Just for fun, though, the for-loops can be eliminated from Andy's solution as follows: [x1,x2]=ndgrid(-10:0.1:10, -10:0.1:10); XX=[x1(:).';x2(:).']; tmp1 = sum( XX.*(A*XX) ); tmp2 = XX'*expm(B); V=bsxfun(@plus, tmp1, tmp2*XX);
From: Stefan on 25 Jul 2010 07:19 Thx for the solution without the for loops. The bigger picture is that there is a second function V2, with matrices A2 & B2. I'm trying to find all the points (x1,x2,x3,x4) where V<V2, and x1,x2,x3,x4 are changing by a 0.1 stepsize. > I'm willing to lay odds that you don't need this and that it would be advisable for you to explain the bigger picture of what you're trying to do. > > Just for fun, though, the for-loops can be eliminated from Andy's solution as follows: > > [x1,x2]=ndgrid(-10:0.1:10, -10:0.1:10); > > XX=[x1(:).';x2(:).']; > > tmp1 = sum( XX.*(A*XX) ); > tmp2 = XX'*expm(B); > > V=bsxfun(@plus, tmp1, tmp2*XX);
From: Matt J on 25 Jul 2010 10:44
"Stefan " <aidematlab(a)yahoo.ca> wrote in message <i2h6j8$659$1(a)fred.mathworks.com>... > Thx for the solution without the for loops. > The bigger picture is that there is a second function V2, with matrices A2 & B2. > I'm trying to find all the points (x1,x2,x3,x4) where V<V2, and x1,x2,x3,x4 are changing by a 0.1 stepsize. ======= That's not really the big picture. The big picture would explain why you think you need all values for all 201^4 combinations of (x1,x2,x3,x4) in memory simultaneously. |