Computational Physics Programming using fortran g95

In summary, the program will need to calculate the integral of sine over a range of intervals, and compare the results using the trapezoid and Simpson methods.
  • #1
jhosamelly
128
0

Homework Statement



Create a program that computes for the value of sine function. Then compute for its
integral from 0 to pi with N intervals, where N=4,8,16,256 and 1024 and compare the
result for the trapezoid and simpson method.


Homework Equations



Trapezoid rule of Integration is (b-a)((f(a)+(f(b))/2)

The Attempt at a Solution


here is the code I made

2lm29mq.jpg


but I'm getting "Unclassifiable statement" at the i1 equation.
Is there something wrong with my code? We are using fortran 90

I'm trying the trapezoid rule 1st.
 
Physics news on Phys.org
  • #2
Drop the '*' in your print statements for the unit specifier
The format part of the print statement should be enclosed in single quotes ['] instead of double quotes ["].

Thus, the first output should be:
print 'SIN(0) = ', sina
 
  • #3
OOPS: forgot format descriptor. First output should be:

print '("SIN(0) = ", F6.2)', sina
 
  • #4
its still not working.. and this is how our prof taught us. we use
print *, "ddd" , ddddd

something wrong with my equation I think.
 
  • #5
Your i1 "equation" is not an equation - it's an assignment statement. An equation expresses the equality of two expressions. That's not what = is used for in programming. Instead, = is used to assign the value of the expression on the right side to the variable on the left side.

Your compile error "unclassifiable statement" comes from not having a multiplication operator. This assignment statement should be
Code:
i1 = (b - a) [color="red"][B]*[/B][/color]((sina + sinb)/2)

You could also write this as
Code:
i1 = (b - a) * (sin(angrada) + sin(angradb))/2

In mathematics you can write a product of two numbers by putting them next to each other, with ##2b## meaning 2 times b.

There's no such shortcut in programming, though. If you need to perform a multiplication, you MUST use *.
 
  • #6
Thank you so much :))))
 
  • #7
Hmmmm.. I can't seem to finish this program I'm doing. :( What should I do with N?
 
  • #8
You are a very long way from being done with this program, I'm afraid.

jhosamelly said:
Create a program that computes for the value of sine function. Then compute for its integral from 0 to pi with N intervals, where N=4,8,16,256 and 1024 and compare the result for the trapezoid and simpson method.

The program will need to compute the value of sine(x) at a number of points in the interval [0, ##\pi##]. One part will need to split this interval into four subintervals, and calculate the integral using the trapezoid method and Simpon's method. The next part will need to do the same thing using eight subintervals.

A third part will need to do the same thing, using 16 subintervals. A fourth part will need to do the same thing using 256 subintervals. Finally, the last part will need to do the same thing using 1024 subintervals.
 

Related to Computational Physics Programming using fortran g95

1. What is computational physics programming?

Computational physics programming is the use of computer algorithms and numerical methods to solve problems in physics. It involves writing code to simulate physical systems and analyze their behavior.

2. Why use Fortran g95 for computational physics programming?

Fortran g95 is a programming language specifically designed for scientific and numerical computation. It has a long history in physics and is known for its high performance and efficient handling of large datasets, making it a popular choice for computational physics programming.

3. What are the advantages of using Fortran g95 over other programming languages?

Fortran g95 has a simple syntax and built-in features for scientific computation, making it easier to write efficient code for physics simulations. It also has a large library of functions and is highly optimized for use with mathematical and scientific calculations.

4. Can Fortran g95 be used for other types of programming besides computational physics?

Yes, Fortran g95 can be used for a variety of scientific and engineering applications, such as weather forecasting, financial modeling, and data analysis. It is also used in some high-performance computing applications.

5. Are there any resources available for learning Fortran g95 for computational physics programming?

Yes, there are many online tutorials, textbooks, and forums dedicated to learning Fortran g95 for computational physics. Some universities also offer courses on this topic. Additionally, the Fortran community is very active and helpful in providing support and resources for beginners.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
7
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
8
Views
2K
  • Programming and Computer Science
Replies
4
Views
653
  • Engineering and Comp Sci Homework Help
Replies
20
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
10
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
6
Views
5K
  • Engineering and Comp Sci Homework Help
Replies
23
Views
2K
  • STEM Academic Advising
Replies
9
Views
1K
Replies
4
Views
833
Back
Top