Child pages
  • Question 25 - Euler method and numerical integration of systems of ODE
Skip to end of metadata
Go to start of metadata

Description of Method

C code
#include<stdio.h>
#include<math.h>

int main(int argc,char*argv[])
{
	int M=10,k=1; /* M number of iterations, k is a counter*/
	float x=2,t=0,h=0.01,x1;/* t=0 initial point, h=1 step*/
	float xexact;
	printf("***********************************************\n\n\n");
	printf("Counter\t\tt+h\t\txexact\tAprox x\n\n");
	for(k=1;k<=M;k++)
	{
		xexact =(4.0/1.3)*(exp(0.8*t) - exp(-.5*t)) + 2*exp(-.5*t);
		x1=4*exp(.8*t)-.5*x;/* x1=f(t,x)=x' */
		x=x+x1*h; /* approximate solution at point t+h*/
		t=t+h;
		printf("%d\t %1.5f\t %1.5f\t%1.5f\n",k,t,xexact,x);
	}
return 0;
}
  • No labels