1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Computational Physics Programming using fortran g95

  1. Nov 30, 2012 #1
    1. The problem statement, all variables and given/known data

    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.


    2. Relevant equations

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

    3. 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.
     
  2. jcsd
  3. Nov 30, 2012 #2

    SteamKing

    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper

    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
     
  4. Nov 30, 2012 #3

    SteamKing

    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper

    OOPS: forgot format descriptor. First output should be:

    print '("SIN(0) = ", F6.2)', sina
     
  5. Nov 30, 2012 #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.
     
  6. Nov 30, 2012 #5

    Mark44

    Staff: Mentor

    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 (Text):
    i1 = (b - a) [color="red"][B]*[/B][/color]((sina + sinb)/2)
     
    You could also write this as
    Code (Text):
    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 *.
     
  7. Nov 30, 2012 #6
    Thank you so much :))))
     
  8. Dec 14, 2012 #7
    Hmmmm.. I can't seem to finish this program I'm doing. :( What should I do with N?
     
  9. Dec 14, 2012 #8

    Mark44

    Staff: Mentor

    You are a very long way from being done with this program, I'm afraid.

    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.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Computational Physics Programming using fortran g95
  1. Fortran Programming (Replies: 5)

Loading...