C C++ CODE : Shooting method for solving boundary value problem

Working C C++  Source code program for Shooting method for solving boundary value problem
#include<iostream.h>
#include<conio.h>
float f1(float ,float,float);
float f2(float, float ,float);
int main()
{
    int i;    float x1,x2,y1,y2,h,z,sy1,sy2,sz1,sz2,temp1,temp2,c[2],d[2];
    clrscr();
    cout<<"Enter x1,y1,x2,y2 ? " ;cin>>x1>>y1>>x2>>y2;
    cout<<"Enter h ? ";cin>>h;
    temp1=x1;
    temp2=y1;

    for(i=0;i<2;i++)
    {
        cout<<"enter z ? ";cin>>z;
        d[i]=z;
        while(x1<=x2-h)
        {
            sy1=f1(x1,y1,z);
            sz1=f2(x1,y1,z);
            sy2=f1(x1+h,y1+h*sy1,z+h*sz1);
            sz2=f2(x1+h,y1+h*sy1,z+h*sz1);
            y1+=h*(sy1+sy2)/2;
            z+=h*(sz1+sz2)/2;
            x1+=h;
            cout<<endl<<x1<<"   "<<y1<<"   "<<z<<"  ";
        }
        c[i]=y1;
        x1=temp1;
        y1=temp2;
    }


    //for(i=0;i<2;i++)
    //cout<<endl<<d[i]<<"   "<<c[i];
    z=(y2-c[0])*(d[1]-d[0])/(c[1]-c[0])+d[0];
    cout<<endl<<z;

    while(x1<=x2-h)
    {

        cout<<endl<<x1<<"   "<<y1<<"   "<<z<<"  ";
        sy1=f1(x1,y1,z);
        sz1=f2(x1,y1,z);
        sy2=f1(x1+h,y1+h*sy1,z+h*sz1);
        sz2=f2(x1+h,y1+h*sy1,z+h*sz1);
        y1+=h*(sy1+sy2)/2;
        z+=h*(sz1+sz2)/2;
        x1+=h;
    }
    getch();
    return 0;
}


float f1(float x,float y,float z)
{
return z;
}


float f2(float x,float y,float z)
{
return 3*x+4*y;
}





4 comments :

  1. temp1=x1
    temp2=y1.. what does it mean?

    ReplyDelete
  2. Temporary = OLD
    BECAUSE YOU WILL HAVE OLD VARIABLE TO OBTAIN NEW ONE ITERTAVILLY.

    ReplyDelete
  3. Could you provide a small description of the same as well?

    ReplyDelete
  4. The programming is little complex could have been more simpler and understandable

    ReplyDelete

Your Comment and Question will help to make this blog better...