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 30 31 32 33 34 35

#include <iostream>
#include <stdio.h>
#include <cmath>
using namespace std;
void step(double *pt, double *px, double h);
double fk(double t, double x);
int main()
{
double t_0 = 0, t = 0, x = 1, h = 0.1;
printf("Equation dx/dt = x solution, when x(0) = 1 \n \nt x exp(t) \n \n");
for(int i = 0; i <= 10; i++)
{
t = t_0 + h * i;
printf("%3.1lf %5.4lf %5.4lf \n", t, x, exp(t));
step(&t, &x, h);
//t++;
}
}
void step(double *pt, double *px, double h)
{
double *px_2;
px_2 = new double;
*px = *px + h * fk(*pt, *px);
*px_2 = *px + h * 0.5 * (fk(*pt, *px) + fk(*pt, *px));
delete px_2;
}
double fk(double t, double x)
{
return x;
}
 