Logo 
Search:

C Programming Articles

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

ADAM-BASHFORTH METHOD

Posted By: Nicole Hughes     Category: C Programming     Views: 4599

Program of ADAM-BASHFORTH METHOD

Code for ADAM-BASHFORTH 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("admbsh.dat","w");
    clrscr();
    printf("ADAM-BASHFORTH METHOD ");
    fprintf(fp,"ADAM-BASHFORTH 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]+(h/24)*((-9*function[count-3])+(37*function[count-2])-(59*function[count-1])+(55*function[count]));
    final=equation(search,yvalue[search]);
    yvalue[search]=yvalue[count]+(h/24)*((function[count-2])-(5*function[count-1])+(19*function[count])+(9*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 ADAM-BASHFORTH METHOD Or get search suggestion and latest updates.

Nicole Hughes
Nicole Hughes author of ADAM-BASHFORTH 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].

 
Shubha Udyawar from India Comment on: Feb 03
plz help me in creating a bill where we hv to display the contents tht r available in the shop. n there shud be an option whether v hv to refill the contents or buy? n den show da entire bill of shopping? plzhelp

View All Comments