/////////////////////////////////////////////////////////////////////////////////
// Solve IVP 
// x''+w²x =  0 , x(0)=0 
// over the interval 0<t<1 with forward Euler method.
///////////////////////////////////////////////////////////////////////////////////
/* 
compile with	
gcc -o aufgabe3c aufgabe3c.c  -L/usr/local/dislin -ldislnc -lm -lX11
*/

#include <stdio.h>
#include <math.h>
#include "/usr/local/dislin/dislin.h"

int main()
{

//--------------------------------------------------
        metafl("PNG"); // output format
	setfil("aufgabe3_001.png"); // name of the output file
	scrmod("REVERS"); // reverse colors
        winsiz(1920,1080); // relosution of image file
	page(2970*2,2970);// define a plot size
//----------------------------------------------------
disini();  //dislin initialisation
       
	float x = 0.0; // initial space point
	float x0 = 0.0;
	float v = 1;
	float v0 = 1;
	float t = 0.0; //initial time
	float h = 0.001; // time step
        float Tend = 63.0; //end of the time interval

        name("time","x"); //axis labels 
        name("space","y");
        hsymbl(10); // size of the symbol
	graf(0.0,Tend+1,0.0,10,-5,5,-5,1.0); // plots a two-dimensional axis system

       setrgb(0,0,1); // set blue color
	while ( t <= Tend ) {
		x0 = x;
		v0 = v;
		x = x0 + h * (v0);
		v = v0 + h * (-x0);
		t = t + h;
		setrgb(0,0,1); // set blue color
		rlsymb(21,t,x); // plot the symbol (t,x)one the plane
	}     

disfin(); //finish dislin 

printf("READY\n"); //print READY at the end of the program
}