Subscripts and Fractions in Fortran 95

  • Context: Fortran 
  • Thread starter Thread starter kathrynag
  • Start date Start date
  • Tags Tags
    Fortran Fractions
Click For Summary
SUMMARY

The discussion focuses on implementing the equation dB=log_10(P_2/P_1) in Fortran 95. Users clarified that subscripts in Fortran are represented as indices of arrays, and the correct syntax for fractions is to use the division operator (/). The example provided demonstrates how to define an array with REAL*8 type and calculate the logarithm of the ratio of two elements, confirming that B=LOG10(P(1)/P(2)) is valid code.

PREREQUISITES
  • Understanding of Fortran 95 syntax
  • Familiarity with array indexing in Fortran
  • Knowledge of logarithmic functions in programming
  • Basic concepts of numerical data types, specifically REAL*8
NEXT STEPS
  • Research Fortran 95 array manipulation techniques
  • Learn about mathematical functions available in Fortran, such as LOG10
  • Explore advanced data types in Fortran, including REAL and INTEGER
  • Study best practices for writing mathematical equations in Fortran
USEFUL FOR

Fortran developers, students learning numerical computing, and anyone implementing mathematical models in Fortran 95.

kathrynag
Messages
595
Reaction score
0
i'm trying to write the equation dB=log_10(P_2/P_1)
I just need help writing this equation into Fortran.
I know for exponents I use **, but what about subscripts?
Also, my inital thought for a fraction is /. Is this correct?
 
Technology news on Phys.org
Do I use 10 log(P2/P1)
 
In fortran, subscripts mean the index of an array.
For an array such as
REAL*8 P(10)
P(1) is the equivalent as what we write as P1, and so on.
So what to write depends on how your variables have been defined.
If you write
Code:
REAL*8 P(2), B
P(1)=20
P(2)=40
B=LOG10(P(1)/P(2))
will be perfectly OK.
 

Similar threads

  • · Replies 20 ·
Replies
20
Views
4K
  • · Replies 17 ·
Replies
17
Views
7K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 17 ·
Replies
17
Views
6K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 16 ·
Replies
16
Views
2K