Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Numerical MethodsRSS Feeds

MODIFIED EULER'S METHOD

Posted By: Faith Hughes     Category: C Programming     Views: 11927

Write a program of MODIFIED EULER'S METHOD.

Code for MODIFIED EULER'S METHOD in C Programming

#include<stdio.h>
#include <math.h>
#include<conio.h>
#define F(x,y)  (x)*(x)+(y)
void main()
{
  double y0,x0,y1,x1,y1_0,a,n,h,f,f1;
  int j,count,flag;
  clrscr();
  printf("\nEnter the value of x0: ");
  scanf("%lf",&x0);
  printf("\nEnter the value of y0: ");
  scanf("%lf",&y0);
  printf("\nEnter the value of h: ");
  scanf("%lf",&h);
  printf("\nEnter the value of last point: ");
  scanf("%lf",&n);
  for(x1=x0+h,j=1; x1<=n+h; x1=x1+h,j++)
  {
    count=0;
    flag=0;
    f=F(x0,y0);
    y1_0 = y0 + (h * f);
    printf("\n\n * * y%d_0 = %.3lf * *",j,y1_0);
     do
      {
    count++;
    f=F(x0,y0);
    f1=F(x1,y1_0);
    y1 = y0 + h/2 * ( f + f1);
    printf("\n\n * * x = %.3lf => y%d_%d = %.3lf * *",x1,j,count,y1);
    if(fabs(y1-y1_0)<0.00001)
     {
      printf("\n\n\n\n * * * * y%d = %.3lf * * * *\n\n",j,y1);
      flag=1;
     }
    else
      y1_0 = y1;
      }while(flag!=1);
    y0 = y1;
  }
getch();
}

/*
OUT PUT
---------

Enter the value of x0: 0

Enter the value of y0: 1

Enter the value of h: 0.05

Enter the value of last point: 0.1


* * y1_0 = 1.050 * *

* * x = 0.050 => y1_1 = 1.051 * *

* * x = 0.050 => y1_2 = 1.051 * *

* * x = 0.050 => y1_3 = 1.051 * *



* * * * y1 = 1.051 * * * *



* * y2_0 = 1.104 * *

* * x = 0.100 => y2_1 = 1.105 * *

* * x = 0.100 => y2_2 = 1.106 * *

* * x = 0.100 => y2_3 = 1.106 * *



* * * * y2 = 1.106 * * * *


*/
  
Share: 


Didn't find what you were looking for? Find more on MODIFIED EULER'S METHOD Or get search suggestion and latest updates.

Faith Hughes
Faith Hughes author of MODIFIED EULER'S METHOD is from London, United Kingdom.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!