Fortran90 How to take the power of elements of an array to, say, 5?

Click For Summary
To raise the elements of an array to a power of 5 in Fortran90, the operation can be performed efficiently using the syntax v = v**5, which applies the power operation element-wise to the array. This method is straightforward and avoids the need for loops, making it suitable for large arrays without significant performance concerns. The discussion highlights that even for extensive computations, modern CPUs can handle these operations quickly, ensuring that the implementation remains efficient regardless of the number of iterations.
stevenphy2
Messages
10
Reaction score
0
Hi all,
as title, how to take the power of elements of an array to, say, 5?
I know how to do it using loops, but would it be very troublesome if I have to do it a thousand times?
Any ready made function in fortran90?
I hope there is...
I have googled it quite a bit, but seems nothing useful.
 
Physics news on Phys.org
I'm not very knowledgeable about what's in or not in Fortran90 libraries, but it's no more troublesome to do it in a loop that runs a thousand times than in one that runs five times. A computer CPU will happily do all these computations in a small fraction of a second. The code to do this would be very simple.
 
Hello,

If v is an array, you can write v=v**5

The power operation will be applied element-wise to the array.

Pete
 

Similar threads

Replies
43
Views
5K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 16 ·
Replies
16
Views
3K
  • · Replies 17 ·
Replies
17
Views
3K
  • · Replies 13 ·
Replies
13
Views
7K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
Replies
7
Views
3K
  • · Replies 3 ·
Replies
3
Views
3K