EULER’S METHOD IN C
Date:-
Write a C program to solve the differential equation
for x=0(0.05)0.4By Euler method correct up to 5 decimal places,given that y=0 for
x=0
Program code:-
#include<stdio.h>
#include<math.h>
float f(float x,float y);
int main()
{
float x0,xn,y0,h;
x0=0;
xn=0.4;
y0=0;
h=0.05;
printf("t xtt yn n");
while(x0<xn)
{
y0=y0+h*f(x0,y0);
x0=x0+h;
printf("%12.5f t %12.5fn",x0,y0);
}
}
float f(float x,float y)
{
float z;
z=(1.+x*y)/(1.+10.*pow(y,2.));
return(z);
}
Output:-
x y
0.05000 0.05000
0.10000 0.09890
0.15000 0.14490
0.20000 0.18712
0.25000 0.22554
0.30000 0.26055
0.35000 0.29266
0.40000 0.32235

Euler method in c

  • 1.
    EULER’S METHOD INC Date:- Write a C program to solve the differential equation for x=0(0.05)0.4By Euler method correct up to 5 decimal places,given that y=0 for x=0 Program code:- #include<stdio.h> #include<math.h> float f(float x,float y); int main() { float x0,xn,y0,h; x0=0; xn=0.4; y0=0; h=0.05; printf("t xtt yn n"); while(x0<xn) { y0=y0+h*f(x0,y0); x0=x0+h; printf("%12.5f t %12.5fn",x0,y0); } } float f(float x,float y) { float z; z=(1.+x*y)/(1.+10.*pow(y,2.)); return(z); }
  • 2.
    Output:- x y 0.05000 0.05000 0.100000.09890 0.15000 0.14490 0.20000 0.18712 0.25000 0.22554 0.30000 0.26055 0.35000 0.29266 0.40000 0.32235