Logo 
Search:

C Programming Articles

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

MILNE'S METHOD

Posted By: Aaron Evans     Category: C Programming     Views: 2877

Program of MILNE'S METHOD.

Code for MILNE'S METHOD in C Programming

#include<stdio.h>
#include<conio.h>
#include<math.h>
#define MAX 20

float equation(float x,float y)
{
    return(1+(y*y));

}

void main()
{
    FILE *fp;
    int i=0,count=-1;
    float lower,upper,h,y1,xvalue[MAX],yvalue[MAX],result;
    float function[MAX],search,final,temp;
    fp=fopen("milne.dat","w");
    clrscr();
    printf("MILNE'S METHOD ");
    fprintf(fp,"MILNE'S METHOD ");
    printf("\n");
    fprintf(fp,"\n");
    printf("\nEnter the lower bound of x  :  ");
    fprintf(fp,"\nEnter the lower bound of x  :  ");
    scanf("%f",&lower);
    fprintf(fp,"%f",lower);
    printf("\nEnter the upper bound of x  :  ");
    fprintf(fp,"\nEnter the upper bound of x  :  ");
    scanf("%f",&upper);
    fprintf(fp,"%f",upper);
    printf("\nEnter the value of y(lower) :  ");
    fprintf(fp,"\nEnter the value of y(lower) :  ");
    scanf("%f",&y1);
    fprintf(fp,"%f",y1);
    printf("\nEnter the value of h        :  ");
    fprintf(fp,"\nEnter the value of h        :  ");
    scanf("%f",&h);
    fprintf(fp,"%f",h);
    printf("\nEnter the value of x for which you want to find y :");
    fprintf(fp,"\nEnter the value of x for which you want to find y :");
    scanf("%f",&search);
    fprintf(fp,"%f",search);
    xvalue[i]=lower;
    yvalue[i]=y1;
    for(i=0;xvalue[i]<=upper;i++)
    {
        xvalue[i+1]=xvalue[i]+h;
    }
    for(i=0;xvalue[i]<=upper;i++)
    {
        result=equation(xvalue[i],yvalue[i]);
        yvalue[i+1]=yvalue[i]+(h*result);
    }
    printf("\n\n");
    fprintf(fp,"\n\n");
    printf("The table is   ");
    fprintf(fp,"The table is   ");
    printf("\n\n");
    fprintf(fp,"\n\n");
    printf(" i     x       y      f(x,y)   ");
    fprintf(fp," i     x       y      f(x,y)   ");
    printf("\n\n");
    fprintf(fp,"\n\n");
    for(i=0;xvalue[i]<=upper;i++)
    {
        function[i]=equation(xvalue[i],yvalue[i]);
        printf(" %d.  %.4f  %.4f  %.4f ",i,xvalue[i],yvalue[i],function[i]);
        fprintf(fp," %d.  %.4f  %.4f  %.4f ",i,xvalue[i],yvalue[i],function[i]);
        count=count+1;
        printf("\n");
        fprintf(fp,"\n");
    }
    yvalue[search]=yvalue[count-3]+(4*h/3)*((2*function[count-2])-(function[count-1])+(2*function[count]));
    final=equation(search,yvalue[search]);
    yvalue[search]=yvalue[count-1]+(h/3)*((function[count-1])+(4*function[count])+final);
    printf("\n\n");
    fprintf(fp,"\n\n");
    printf("Approximate value is :  %.4f  ",yvalue[search]);
    fprintf(fp,"Approximate value is :  %.4f  ",yvalue[search]);
    fclose(fp);
    getch();
}
  
Share: 


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

Aaron Evans
Aaron Evans author of MILNE'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!