top of page
Wave
Cactus%20Plant_edited.jpg

EULER'S METHOD

//Solve by Euler's method dy/dx=(1+x^2)y where y(0)=1 and x=0(0.2)0.6


#include<stdio.h>
#include<math.h>
float f(float x, float y)
{
    return (1+(x*x))*y;
}
int main()
{
    float x,y,xf,h,p,q;
    int i=0;
    printf("Enter the initial value of x : ");
    scanf("%f",&x);
    printf("\nEnter the initial value of y : ");
    scanf("%f",&y);
    printf("\nEnter the final value of x : ");
    scanf("%f",&xf);
    printf("\nEnter the value of step length (h) : ");
    scanf("%f",&h);
    printf("\n\n Ite\t   Xi\t\t   Yi\t\t   Yi+1\n");
    printf("------------------------------------------------");
    while(x<xf)
    {
        q=y;
        p=x;
        y=y+h*f(x,y);
        x=x+h;
        printf("\n%3d\t%f\t%f\t%f",i++,p,q,y);
    }
    printf("\n\n\nThe result of Y(%.3f) = %f\n",x,y);
}

Subscribe Form

Thanks for submitting!

  • Facebook
  • YouTube
  • Instagram
  • Twitter

©2020 by Abhisek Midya ( A18 )

bottom of page