Runge-Kutta second-order method

Aug 5, 2008 at 2:30pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
    double t,x,h=0.1;
    

//output loop--
for(int i=0;i<=10;i++){
        printf(   ,t,x,exp(-t));
        step(t,x,h); //integration
        }
//--

}
//**
void step(double *pt, double *px, double h)
{
     
     f = fk(t,x)
     
     }
//**
double fk(double t,double x)
{
       return -x;
       }
//** 

I should get an answer:
dx/dt = -x answer, when x(0)=1 is:
t X Exp(-t)
0.0 1.0000 1.000
0.1 0.9050 0.9048
0.2 0.8190 0.8187
0.3 0.7412 0.7408
0.4 0.6708 0.6703
0.5 0.6071 0.6065
0.6 0.5494 0.5488
0.7 0.4972 0.4966
0.8 0.4500 0.4493
0.9 0.4072 0.4066
1.0 0.3685 0.3679


Help please.
Last edited on Aug 5, 2008 at 4:56pm
Aug 5, 2008 at 2:44pm
What you do has nothing to do with the Runge-Kutta-Method. I reccomend that you look up the formula (most likely you want four step, fourth order method. For a change, the formula on Wikipedia seems to be OK)

Edit. I didn't see that you wanted to use the second order method. I don't know the formula for it, but it seems evident that your code does not use the relevant data (e.g. h&t).
Since the second-order method is not too common, I suggest that you post the formula or a link to it.
Last edited on Aug 5, 2008 at 2:50pm
Aug 5, 2008 at 4:36pm
Aug 5, 2008 at 4:58pm
I still don't see where you try to put these formulas into action...
Aug 5, 2008 at 5:33pm
I didn't try , cos I don't know , not a math guy , so I asked for help , where to put em'
Aug 5, 2008 at 5:46pm
May I ask why you want us to implement it for you? There are libraries that solve ordinary differential equations better than anyone here is able to do in a posting (there are some numerical problems which do not allow a simple "hack in the formula and you are done"-approach).
Topic archived. No new replies allowed.