Re: How can I speed up this 'for' loop?



Ian Cowley wrote:
>
>
> In message XlOFe.161998$tt5.48841@edtnps90, Paul Skoczylas burbled:
>> "Ian Cowley" <me3@xxxxxxxxxxx> wrote in message
>> news:dc875i$9ac$1@xxxxxxxxxxxxxxxxxxxxxxx
>>> In message ef0f0b3.-1@xxxxxxxxxxxxxxxx, Geoff Zilahy
burbled:
>>>> hi everyone, I'm just trying to speed up this for loop:
>>>>
>>>> %
>>>> for m = 1:M
>>>> b = sH_2*u;
>>>> b = b(:);
>>>> u = sH_1\b;
>>>> end
>>>
>>> You're not actually changing anything inside the loop, so
doing
> it
>>> once willgive you the same values of u and b.
>>>
>>> If you post your code with all the bits in it where stuff
is
>>> changing from one loop to the next, then we could help a
bit
> more.
>>> At presetn the code you posted just does the exact same
> calculation
>>> M times, so you can speed it up by a factor of M by just
doing
> it
>>> once :)
>>
>>
>> Either I'm missing something, or Ian is! Assuming that u has a
>> defined value coming into the loop, then b and u both change at
> each
>> iteration.
>
> Ah yes, didn't see that u and b were changing each other. I hadn't
> realised
> it was looping over time - I assumed it was looping over the
> elements of M
> and working something out for each one. My bad :)
>
> --
> Ian Cowley
> Bishop's Stortford/Cambridge, UK
>
> www.iancowley.co.uk/contact
>
>
>
Hi Paul and Ian,

This is the same problem as before (Geoff Halstead), and I was just
looking to see if the b part of the loop could be speeded up in the
same way as the u part.
In terms of the boundary conditions, I'm currently working on
implimenting more specific coefficients for surface and corner nodes.
As far as types of boundaries go, I'm trying to model 3 different
ones at the moment:

boundary at a set temp -
for this one, I'm setting all the elements in the row of the H
matrices which correspond to the boundary node of u to zero. Then
resetting the leading diagonal element of this row to 1 (i.e. no
change)

free boundary (allowed to rise and fall in temp) -
here i'm leaving the row of the H matrices which correspond to the
boundary node of u in it's original state. (not sure if this is
correct)

heat flux in/out -
i'm tring to add a heat flux coefficient to the nodes on this type of
boundary. Not sure how to change the corresponding row of the H
matrices.

Thanks for your help guys,

Geoff Halstead/zilahy :)
.



Relevant Pages

  • Re: Math libarary
    ... thought would have been a bette routine than Math.Exp and I was wrong;/ ... Both of these depend on S only but have to take into account the boundaries. ... Right now I have two functions that essentially loop over S seperately. ... The following is the code I use to compute the laplacian of a scalar field. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Stupid Question-- Why not Open-loop?
    ... > If closed- or open loop doesn't apply to a hammer, ... If not scooter, to a bicycle? ... The first thing to realise about a system is where the boundaries are going ...
    (sci.engr.control)
  • Re: How can I speed up this for loop?
    ... > You're not actually changing anything inside the loop, ... i am currently at a standstill with how to develope boundaries with ... % set the boundary conditions for the plate ... % set boundary condition values for H_1 ...
    (comp.soft-sys.matlab)
  • Boundary tracing and mask creation
    ... and then keep the brightness data inside them in a separate matrix. ... I first use the bwboundaries command to trace their boundaries, ... I am a total beginner in matlab so, I think my mistake lies in the ... 3rd line of the loop, which as I said I saw from the example. ...
    (comp.soft-sys.matlab)
  • Re: How can I speed up this for loop?
    ... >> changing from one loop to the next, then we could help a bit more. ... > iteration. ... it was looping over time - I assumed it was looping over the elements of M ... Ian Cowley ...
    (comp.soft-sys.matlab)