You are on page 1of 2

//Euler's Modified Method for differential equation

#include <iostream>

#include <math.h>

#include <iomanip>

double function(float x,float y)

return x + y;

using namespace std;

int main ()

{ float c, x, y, h, yn, xn;

cout<<"\n\t\tThis Program Solves Differential Equation using Modified Euler's


Method"<<endl;

cout<<"Give the intital value of x and corresponding y \n\t";

cout<<"x = ";cin>>x;

cout<<"\n\ty = ";cin>>y;

cout<<"\nFor what Value of x you want to find the value of y ? ";cin>>c;

cout<<"What stepsize do you want to use ? ";cin>>h;

int n = c/h;

for (int i =1;i<=n;i++)

{ yn = y;

xn = x;

y = y + h*function(x,y);

x = x +h;

cout<<"\n\nBy Euler's Method at x = "<< x <<", y is : "<<y<<endl;

cout<<"-------------------------------------"<<endl;

cout<<"** Using Modified Euler's Method **"<<endl;

for (int j=1;j<10;j++)

cout<<"For "<<j<<"th Iteration y is :";

y = yn + (h/2)*(function(x,y) + function(xn,yn));
cout<<y<<endl;

//Displaying the result;

cout<<"\n\tThus the value of y at x = "<<c<<" is : "<<y;

You might also like