|
|
Up |
|
|
  |
Date: Apr 19, 2008 17:58
What would be the shortest way to sum some elements of an array? For
example from 5 to 50.
I know the "obvious" way to do it:
s=0.
do 1 i=5,50
s=s+a(i)
1 continue
but since I'm currently doing something which requires quite a number
of summing, I was wondering is there something shorter ?
Any idead appreciated
regards
Luka
|
| |
|
| | 26 Comments |
|
  |
Author: Craig DedoCraig Dedo Date: Apr 19, 2008 18:40
"Luka Djigas" gmail.com> wrote in message
news:pu4l04dnt3apg1hf1a1jvesp0gf3jttiol@4ax.com...
> What would be the shortest way to sum some elements of an array? For
> example from 5 to 50.
>
> I know the "obvious" way to do it:
> s=0.
> do 1 i=5,50
> s=s+a(i)
> 1 continue
>
> but since I'm currently doing something which requires quite a number
> of summing, I was wondering is there something shorter ?
>
> Any idead appreciated
>
> regards
> Luka
|
| Show full article (1.00Kb) |
|
| | no comments |
|
  |
Author: dongyuanxundongyuanxun Date: Apr 19, 2008 21:10
On Apr 20, 8:58 am, Luka Djigas gmail.com> wrote:
> What would be the shortest way to sum some elements of an array? For
> example from 5 to 50.
>
> I know the "obvious" way to do it:
> s=0.
> do 1 i=5,50
> s=s+a(i)
> 1 continue
>
> but since I'm currently doing something which requires quite a number
> of summing, I was wondering is there something shorter ?
>
> Any idead appreciated
>
> regards
> Luka
You can also prepare a function called sum(),if your IDE doesn't
support the sum() intrinsic function.
|
| |
| no comments |
|
  |
Author: Gerry FordGerry Ford Date: Apr 19, 2008 21:12
"Craig Dedo" wi.rr.com> wrote in message
news:480a9ef9$0$7077$4c368faf@roadrunner.com...
> "Luka Djigas" gmail.com> wrote in message
> news:pu4l04dnt3apg1hf1a1jvesp0gf3jttiol@4ax.com...
>> What would be the shortest way to sum some elements of an array? For
>> example from 5 to 50.
>>
>> I know the "obvious" way to do it:
>> s=0.
>> do 1 i=5,50
>> s=s+a(i)
>> 1 continue
>>
>> but since I'm currently doing something which requires quite a number
>> of summing, I was wondering is there something shorter ?
>>
>> Any idead appreciated
>>
>> regards
>> Luka ...
|
| Show full article (1.27Kb) |
| no comments |
|
  |
Author: dongyuanxundongyuanxun Date: Apr 19, 2008 21:19
On Apr 20, 12:12 pm, "Gerry Ford" wrote:
> "Craig Dedo" wi.rr.com> wrote in message
>
> news:480a9ef9$0$7077$4c368faf@roadrunner.com...
>
>
>
>
>
>> "Luka Djigas" gmail.com> wrote in message
>>news:pu4l04dnt3apg1hf1a1jvesp0gf3jttiol@4ax.com...
>>> What would be the shortest way to sum some elements of an array? For
>>> example from 5 to 50.
>
>>> I know the "obvious" way to do it:
>>> s=0.
>>> do 1 i=5,50
>>> s=s+a(i)
>>> 1 continue
> ...
|
| Show full article (1.54Kb) |
| no comments |
|
  |
Author: nospamnospam Date: Apr 19, 2008 21:29
dongyuanxun gmail.com> wrote:
> On Apr 20, 12:12 pm, "Gerry Ford" wrote:
>> real(dim =50):: a
> That looks that your Compiler doesn't support the dim sign. Try
> "real :: a(50)",please.
Nor would I expect any compiler to support it.
1. It is spelled dimension rather than dim. (This isn't basic)
2. There are quite a large number of places where one can specify
dimension, but in parens after a type name is not one of them. That
would be a type parameter. The real type does not have a type parameter
named dim (or dimension either). Its only type parameter is named kind.
--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
|
| |
| no comments |
|
  |
Author: dongyuanxundongyuanxun Date: Apr 19, 2008 21:37
On Apr 20, 12:29 pm, nos...@see.signature (Richard Maine) wrote:
> dongyuanxun gmail.com> wrote:
>> On Apr 20, 12:12 pm, "Gerry Ford" wrote:
>>> real(dim =50):: a
>> That looks that your Compiler doesn't support the dim sign. Try
>> "real :: a(50)",please.
>
> Nor would I expect any compiler to support it.
>
> 1. It is spelled dimension rather than dim. (This isn't basic)
>
> 2. There are quite a large number of places where one can specify
> dimension, but in parens after a type name is not one of them. That
> would be a type parameter. The real type does not have a type parameter
> named dim (or dimension either). Its only type parameter is named kind.
>
> --
> Richard Maine | Good judgement comes from experience;
> email: last name at domain . net | experience comes from bad judgement.
> domain: summertriangle | -- Mark Twain ...
|
| Show full article (0.99Kb) |
| no comments |
|
  |
Author: Gerry FordGerry Ford Date: Apr 19, 2008 23:29
"Richard Maine" wrote in message
news:1ifny75.cq0wgnblsypaN%%nospam@see.signature...
> dongyuanxun gmail.com> wrote:
>
>> On Apr 20, 12:12 pm, "Gerry Ford" wrote:
>
>>> real(dim =50):: a
>
>> That looks that your Compiler doesn't support the dim sign. Try
>> "real :: a(50)",please.
>
> Nor would I expect any compiler to support it.
>
> 1. It is spelled dimension rather than dim. (This isn't basic)
>
> 2. There are quite a large number of places where one can specify
> dimension, but in parens after a type name is not one of them. That
> would be a type parameter. The real type does not have a type parameter
> named dim (or dimension either). Its only type parameter is named kind.
|
| Show full article (1.30Kb) |
| no comments |
|
  |
Date: Apr 20, 2008 07:07
On Sat, 19 Apr 2008 20:40:11 -0500, "Craig Dedo" wi.rr.com>
wrote:
> This most likely is a homework assignment. However, if I am mistaken and
>Luka is new to Fortran . . .
Nope, not homework assignment.
Well, it's work, and I'm doing it at home, but I don't think that
counts ...
>
> There is always the SUM() intrinsic function. It can sum an array along any
>dimension or the whole array and can even sum those array elements for which the
>value of a corresponding MASK array is true. RTFM.
I know about the sum intristic. Never used it though. I don't like
using intristics where I can do it by plain loop or something (ok, I
don't do the sinus function that way) ... that way I don't have to
think when I'm reading the code next time, what exactly does the
specified intristic do.
|
| Show full article (1.05Kb) |
| no comments |
|
  |
|
|
  |
Date: Apr 20, 2008 07:30
On Sat, 19 Apr 2008 21:10:10 -0700 (PDT), dongyuanxun
gmail.com> wrote:
> You can also prepare a function called sum(),if your IDE doesn't
>support the sum() intrinsic function.
Uhmm, I don't think that IDE has much to do with it. You probably ment
the compiler.
About the function. That is always the possibility. Unfortunately
(unfortunately? :-) my compiler (cvf66c) does support the sum
intristic, but looks like I understood it's capabilities the wrong
way. I didn't understood the mask option.
As far as I have gone with the sum intristic is that it can summ all
elements in specified dimensions of an array.
I didn't understand (no examples in help either) how can one sum just
some elements from an array ...
regards
Luka
|
| Show full article (1.18Kb) |
| no comments |
|
RELATED THREADS |
  |
|
|
|
|
|