Subscripts and Fractions in Fortran 95

In summary, the conversation is about writing the equation dB=log_10(P_2/P_1) in Fortran. The speaker is wondering about using subscripts and fractions in the language. The expert explains that in Fortran, subscripts refer to the index of an array and gives an example of how to write the equation using variables defined in the code.
  • #1
kathrynag
598
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
  • #2
Do I use 10 log(P2/P1)
 
  • #3
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.
 

Related to Subscripts and Fractions in Fortran 95

1. What are subscripts in Fortran 95?

Subscripts in Fortran 95 are used to access or refer to individual elements in an array. They are enclosed in parentheses and placed after the array name, separated by commas if there are multiple dimensions.

2. How are subscripts used in Fortran 95?

Subscripts are used to specify the position of an element in an array. They can also be used in mathematical operations, such as adding or subtracting a constant value to all elements in an array.

3. Can subscripts be negative in Fortran 95?

Yes, subscripts can be negative in Fortran 95. This is useful for accessing elements in an array in reverse order.

4. What are fractions in Fortran 95?

Fractions in Fortran 95 refer to the division of two integers. The result of a fraction operation is a real number, even if both operands are integers.

5. How are fractions used in Fortran 95?

Fractions can be used in mathematical expressions and assignments in Fortran 95. They are also commonly used in scientific and engineering applications to represent precise values.

Similar threads

  • Programming and Computer Science
Replies
20
Views
3K
  • Programming and Computer Science
Replies
8
Views
2K
  • Programming and Computer Science
Replies
17
Views
5K
  • Programming and Computer Science
Replies
17
Views
4K
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
1
Views
949
  • Programming and Computer Science
Replies
5
Views
4K
  • Programming and Computer Science
Replies
4
Views
2K
  • Programming and Computer Science
Replies
16
Views
2K
  • Programming and Computer Science
Replies
8
Views
3K
Back
Top