//  Gerry Brönnimann, ib03

class Runge4{

	// Anfangsbedingungen
	static double y0 = 5;
	static double t0 = 0;
	static double tE = 50;
	static int n = 50;

	static double []t = new double[n+1];
	static double [][]w = new double[2][n+1];

	// definiert die zu integrierende Funktion f
	static double f(double x, double y)
	{
		return (double)(Math.cos(2*x)+Math.cos(3*x) );
	}


	// Runge Kutta-Verfahren 4. Ordnung
	static void runge(double y0, double t0, double tE, int n)
	{
		double h = (tE - t0)/n;
		t[0] = t0;
		w[1][0] = y0;

		for (int i=0; i<n; i++)
		{
			double k1 = h*f( t[i]      , w[1][i]);
			double k2 = h*f( t[i]+h/2.0, w[1][i]+k1/2.0);
			double k3 = h*f( t[i]+h/2.0, w[1][i]+k2/2.0);
			double k4 = h*f( t[i]+h    , w[1][i]+k3);
			t[i+1]=t[i]+h;
			w[1][i+1] = w[1][i] + 1.0/6.0*(k1+2*k2+2*k3+k4);

		}
	}

	// Ausgabe Tabelle
	static void plot()
	{
		for (int j=0; j<w[0].length; j++)
		{
			System.out.println("x: " + t[j]+"  "+"w[1]["+j+"]: "+w[1][j]); //
		}
	}

	public static void main(String[] args)
	{
		runge(y0, t0,tE,n);
		plot();
	}
}