From: Stefan on 23 Jul 2010 15:39 thx for these remarks. But i don't see how to do what you suggested. I also have [x1;x2]'*expm(B)*[x3;x4] to compute. Walter Roberson <roberson(a)hushmail.com> wrote in message <i2cqal$ra0$1(a)canopus.cc.umanitoba.ca>... > Stefan wrote: > > > > for x1 = -10:0.1:10; > > Before this statement we already had enough information to calculate expm(B) > > > for x2 = -10:0.1:10; > > After that statement we have enough information to calculate > > [x1;x2]'*A*[x1;x2] > > > for x3 = -10:0.1:10; > > for x4 = -10:0.1:10; > > V =[x1;x2]'*A*[x1;x2] + [x1;x2]'*expm(B)*[x3;x4] > > No need to do all those calculations here: as indicated above some of this can > be pre-calculated. > > > end > > end > > end > > end > > After using the above hints, you might find ways to vectorize more of the > calculations.
From: Steven_Lord on 23 Jul 2010 15:50 "Stefan " <aidematlab(a)yahoo.ca> wrote in message news:i2cr4t$7oq$1(a)fred.mathworks.com... > thx for these remarks. > But i don't see how to do what you suggested. I also have > [x1;x2]'*expm(B)*[x3;x4] to compute. Does expm(B) depend on any of x1, x2, x3, or x4? If not, why compute it inside those loops? You're computing that quantity 201^4 times -- you only need to calculate it once, and then you can USE it as often as you need to use it. That's what Walter was alluding to. Anyway, related to Roger's question later in the thread -- do you actually need all 201^4 values of V or is the code correct and you only need the value of V corresponding to the situation where all of x1, x2, x3, and x4 are equal to 10? If the latter, only calculate that one value of V and your computation will be complete MUCH, MUCH more quickly. -- Steve Lord slord(a)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
From: Andy on 23 Jul 2010 15:58 You could rewrite it as: B=expm(B); % so you calculate this only once, right at the start for x1 = -10:0.1:10; for x2 = -10:0.1:10; tmp1 = [x1;x2]'*A*[x1;x2]; tmp2 = [x1;x2]'*B; for x3 = -10:0.1:10; for x4 = -10:0.1:10; V =tmp1 + tmp2*[x3;x4]; % <- note the added semicolon end end end end But keep in mind that you overwrite V every time, as Roger points out. So why don't you tell us what you're actually trying to do? Then there may be a way to remove the for loops entirely.
From: Stefan on 23 Jul 2010 16:04 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. "Steven_Lord" <slord(a)mathworks.com> wrote in message <i2crpp$jcj$1(a)fred.mathworks.com>... > > > "Stefan " <aidematlab(a)yahoo.ca> wrote in message > news:i2cr4t$7oq$1(a)fred.mathworks.com... > > thx for these remarks. > > But i don't see how to do what you suggested. I also have > > [x1;x2]'*expm(B)*[x3;x4] to compute. > > Does expm(B) depend on any of x1, x2, x3, or x4? If not, why compute it > inside those loops? > > You're computing that quantity 201^4 times -- you only need to calculate it > once, and then you can USE it as often as you need to use it. That's what > Walter was alluding to. > > Anyway, related to Roger's question later in the thread -- do you actually > need all 201^4 values of V or is the code correct and you only need the > value of V corresponding to the situation where all of x1, x2, x3, and x4 > are equal to 10? If the latter, only calculate that one value of V and your > computation will be complete MUCH, MUCH more quickly. > > -- > Steve Lord > slord(a)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
From: James Tursa on 23 Jul 2010 16:40 "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. Why? Do you need all of them at the same time? What are you doing with V in your code? James Tursa
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 Prev: MATLAB closes automatically Next: Meshgrid for non-zero values |