How to Add a Vector to a 2D Array in Fortran 90?

  • Context: Fortran 
  • Thread starter Thread starter dwnlder
  • Start date Start date
  • Tags Tags
    2d Array Vector
Click For Summary
SUMMARY

In Fortran 90, adding a vector to a 2D array can be simplified by using array operations instead of traditional DO loops. The user suggests that instead of using the loop construct, a more concise syntax like a(:, :) = a(:, :) + b(:) can be employed to achieve the same result. This approach enhances code readability and efficiency. Additionally, creating a custom operator or function is recommended for further simplification.

PREREQUISITES
  • Understanding of Fortran 90 syntax and array manipulation
  • Familiarity with vector and matrix operations
  • Knowledge of custom functions and operators in Fortran
  • Basic programming concepts related to loops and array indexing
NEXT STEPS
  • Research Fortran 90 array operations and their syntax
  • Learn how to create custom operators in Fortran 90
  • Explore the use of functions for array manipulation in Fortran
  • Investigate performance implications of array operations versus loops in Fortran
USEFUL FOR

Fortran developers, computational scientists, and anyone looking to optimize array manipulations in Fortran 90.

dwnlder
Messages
1
Reaction score
0
hi. i have a quick question regarding fortran 90. i often need to add a vector to a 2d dimensional array, and i find it a bit to 'bulky' to always use do loops.

let's say i have this:
Code:
do i=1, 20
   a(:, i)=a(:, i)+b(:)
end do

is there a simple(r) way to tell fortran that i want to add the values to the 'first' value of the array? so i could use something as simple as
Code:
a(:, :)=a(:, :)+b(:)

thx in advance for the answers and suggestions.
 
Technology news on Phys.org
You could either write a quick FUNCTION or perhaps define a custom operator.
 

Similar threads

  • · Replies 20 ·
Replies
20
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
8K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 37 ·
2
Replies
37
Views
5K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 11 ·
Replies
11
Views
3K