Page 1 of 1

Homework 8, due Monday, November 3.

Posted: Fri Oct 31, 2008 3:30 pm
by goodwine
  1. Write a program in FORTRAN, C, C++ or Java to determine an approximate numerical solution to
    • Image
    The program should use the 4th order Runge-Kutta method and have all the variables and functions declared as double precision.
    • Use the term 1.0/6.0 in your code (multiplying the sum of the 4 "k" and "l" terms) and time steps of 0.01 and 0.005. Does the error chance as expected?
    • Use the term 1.0D0/6.0D0 in your code for the same time steps. Does the error change as expected? Explain any difference from what you saw with 1.0/6.0.
  2. Write a computer program in FORTRAN, C, C++ or Java to determine an approximate numerical solution to
    • Image
    Also assume the initial condition for the second derivative is zero.
    The program should use the 4th order Runge-Kutta method.

Re: Homework 8, due Monday, November 3.

Posted: Sat Nov 01, 2008 12:10 pm
by mzenz
I am coding in C++, so I was wondering if I still needed to do the 1.0d0/6.0d0 because I am not sure how real and integer precision works in C++. And if I do need to do this is the code the same?

Re: Homework 8, due Monday, November 3.

Posted: Sat Nov 01, 2008 6:11 pm
by goodwine
mzenz wrote:I am coding in C++, so I was wondering if I still needed to do the 1.0d0/6.0d0 because I am not sure how real and integer precision works in C++. And if I do need to do this is the code the same?
Well, you can't do the "D" part, but do it with and without double precision. If you are not sure how it works in C++, that's something you need to figure out.

Re: Homework 8, due Monday, November 3.

Posted: Sat Nov 01, 2008 11:09 pm
by pburns3
You do not give an intial condition for d2x/dt2 in problem two. Are we supposed to find this somehow or is it missing from the problem statement?

Re: Homework 8, due Monday, November 3.

Posted: Sun Nov 02, 2008 7:00 am
by goodwine
pburns3 wrote:You do not give an intial condition for d2x/dt2 in problem two. Are we supposed to find this somehow or is it missing from the problem statement?
Sorry, it's missing. You may assume it is zero.

Re: Homework 8, due Monday, November 3.

Posted: Sun Nov 02, 2008 1:08 pm
by amrugala
I don't think the pgf77 compiler likes some of the code for the R-K problems... I compiled my code with it and got a straight line at x(t) = 1, whereas with f77 I actually got a graph. Could there be a problem with my code or is it just the compiler?

Re: Homework 8, due Monday, November 3.

Posted: Sun Nov 02, 2008 2:09 pm
by xdong
I am having the exact same problem

Re: Homework 8, due Monday, November 3.

Posted: Sun Nov 02, 2008 3:42 pm
by jnelso10
I see no difference when I include or don't include the D0 with either time step. What is D0 generally supposed to do when you add it?

Re: Homework 8, due Monday, November 3.

Posted: Sun Nov 02, 2008 3:50 pm
by jnelso10
I figured out what the D notation means. When D0 is not included, should x(1) and x(2) only be single precision?

Mt solutions are still the same with and without D0.

Re: Homework 8, due Monday, November 3.

Posted: Sun Nov 02, 2008 5:09 pm
by goodwine
amrugala wrote:I don't think the pgf77 compiler likes some of the code for the R-K problems... I compiled my code with it and got a straight line at x(t) = 1, whereas with f77 I actually got a graph. Could there be a problem with my code or is it just the compiler?
There may be differences in the compilers and it may be the case that pgf77 is smart enough to consider constants that multiply something as the correct precision. I don't know for sure and won't be able to check it before tomorrow, so if there isn't any difference for you, then I would probably just leave it at that.

I can't see how it would give a constant solution, though. I suspect that is a problem with your code.

Re: Homework 8, due Monday, November 3.

Posted: Sun Nov 02, 2008 10:27 pm
by gtorrisi
for the 2nd part of the homework, do we need to turn in a graph of the solution and show what the actual solution is, or just write the computer program and submit the code?

Re: Homework 8, due Monday, November 3.

Posted: Mon Nov 03, 2008 7:21 am
by goodwine
gtorrisi wrote:for the 2nd part of the homework, do we need to turn in a graph of the solution and show what the actual solution is, or just write the computer program and submit the code?
Unless a problem says otherwise, you should always submit a plot of the solution too.