This is how im currently looking so thankyou as the program is working better then before but im still having troubles with y i should be producing a results that when plotted look like an exp decrease , but at least now they're plotting something any further suggestions would result in a prize of me hailing you "King or Queen" depending on your mood
Code:
/* A Runge-Kutta Method for solving Differential Equations*/
/* dy/dt = -y(t), y(0)=1, 0<=x<=5, start h=0.1*/
#include <stdio.h>
#define dist 0.1 /* stepsize */
#define xf 5 /* max for x */
FILE *output; /* internal filename */
double rkutta( double x, double y, double h); /*Runge Kutta Function */
double F(double x, double y); /*Function derivative*/
main()
{
double t, y, h;
int n;
output=fopen("xydata.dat", "w"); /* External filename */
h=0.1;
y=1; /* Initial condition */
fprintf(output, "0\t%f\n", y);
for (n=0;dist*n<=xf;n++) /* The time loop */
{
t=n*dist;
y=rkutta(t, y, dist);
fprintf (output, "%f\t%f\n", t, y);
}
fclose(output);
} /* End of main function*/
double rkutta(double x, double y, double h) /*Called on RK function*/
{
double yn, k1, k2, k3, k4;
double H = h/2.0;
k1 = (h*F(x, y));
k2 = (h*F(x+H, y+(k1/2)));
k3 = (h*F(x+H, y+(k2/2)));
k4 = (h*F(x+h, y+k3));
return(y+=(y+(k1+2*k2+2*k3+k4)*1/6));
}
double F(double x, double y) /*Called on derivative*/
{
if (x==0){
return(-y);
}
}