/*=================================================*/simultaneous (two first order) differential equation /* this is Runge Kutta 2nd order method to find solution of simultaneous diffrential equation of type: dy/dx = f(x,y,z) dz/dx = g(x,y,z) with the initial conditions y(0) = 0, z(0) = 1.0 See Book Rajaraman Page-181 for algorithm and page 185 for the exercise problem which I solve here.. ================= the code starts from the below line =============*/ #include <stdio.h> #include <math.h> main() { int n=1000; int i; float s1,s2,p1,p2,x2,y2,z2; float func(float, float,float); float gfn(float, float, float);/* Now put the boundary condition */ float x1 = 0.0; float y1 = 0.0; float z1 = 1.0; float xf = 0.5; float h; /* h is increment *//*=============================================*/ h=(xf-x1)/n; /* h is increment along x axis */ FILE *f1=fopen("data--simultaneous-eqn-rk2.dat","w"); /*this is the data file to store x,y,z*/ for(i=1; i<=n; i++) { s1=func(x1,y1,z1); p1=gfn(x1,y1,z1); x2=x1+h; s2=func(x2,y1+h*s1,z1+h*p1); p2=gfn(x2,y1+h*s1,z1+h*p1); y2=y1+h*(s1+s2)/2.0; z2=z1+h*(p1+p2)/2.0; fprintf(f1,"%d %f %f %f \n",i,x2,y2,z2); x1=x2; y1=y2; z1=z2; } return(0); } /*== the function f(x,y) is defined as dy/dx = f(x,y,z)and f(x,y,z) =-x-y*y is written as below ===*/ float func(float x, float y,float z) { float fn; fn=-x-y*z; return(fn); }/*== the function f(x,y) is defined as dz/dx = g(x,y,z)and g(x,y,z) =-y-x*z is written as below ===*/ float gfn(float x, float y,float z) { float gn; gn=-y-x*z; return(gn); }/*=================================================*/