/////////////////////////////////////////////////////////////////////////////////
// Solve IVP 
// x'=t-x^2 , x(0)=0 
// over the interval 0<t<900 with forward Euler method.
// The time step h=0.05.
///////////////////////////////////////////////////////////////////////////////////
/*compile with	
gcc -o aufgabe2 aufgabe2.c  -L/usr/local/dislin -ldislnc -lm -lX11
or
gcc -std=c99 -o aufgabe2  aufgabe2.c -I(DISLIN_PATH) -L(DISLIN_PATH) -ldislin
*/

#include <stdio.h>
#include <math.h>
#include "/usr/local/dislin/dislin.h"  /*path to the dislin library*/

int main()
{
       metafl("XWIN");  // output into (small) screen
       //metafl("CONS"); // output into full screen
        scrmod("REVERS"); // reverse colors; works for screen output, PS, TIFF and PNG files
//--------------------------------------------------
   /*     metafl("PNG"); // output format
	setfil("test.png"); // name of the output file
	scrmod("REVERS"); // reverse colors
        winsiz(1280,640); // relosution of image file
	page(2970*2,2970);// define a plot size*/
//----------------------------------------------------
        float x = 0.0; // initial space point
	float t = 0.0; //initial time
	float h = 0.05; // time step
        float Tend = 900.0; //end of the time interval
disini();  //dislin initialisation

        name("time","x"); //axis labels 
        name("space","y");
        hsymbl(10); // size of the symbol
	graf(0.0,Tend+1,0.0,100.0,-30.0,50.0,-30.0,10.0); // plots a two-dimensional axis system
        setrgb(1,0,0); // set red color
        titlin("Breakdown of the forward Euler's method",1); // title
        height(40); 
        title();

       setrgb(0,0,1); // set blue color
	while ( t <= Tend ) {
		x = x + h * (t-pow(x,2));
		t = t + h;
		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
}