C++ Program for Euler’s Method to solve an ODE(Ordinary Differential Equation)

//Eulers Method to solve a differential equation
#include
#include
#include
using namespace std;
double df(double x, double y)            //function for defining dy/dx
{
    double a=x+y;                //dy/dx=x+y
    return a;
}
int main()
{
    int n;   
    double x0,y0,x,y,h;            //for initial values, width, etc.
    cout.precision(5);            //for precision
    cout.setf(ios::fixed);               
    cout<<"\nEnter the initial values of x and y respectively:\n";        //Initial values
    cin>>x0>>y0;                           
    cout<<"\nFor what value of x do you want to find the value of y\n";   
    cin>>x;
    cout<<"\nEnter the width of the sub-interval:\n";            //input width
    cin>>h;
    cout<<"x"<0.0000001)        //I couldn't just write "while(x0

For dy/dx=-2x-y
euler 2 output
For dy/dx=x+y
euler_output_1

Explanation of the Code:

[wpedon id="7041" align="center"]

3 thoughts on “C++ Program for Euler’s Method to solve an ODE(Ordinary Differential Equation)

  1. Hello
    My son teacher have told them to program a program in C++ which can solve non-homogenous problems in differential eq. I tried best to teach him but couldnt solve it

    Can i have a program or tutorial?

  2. Hey ! Do you work as a freelancer? I need help with a project. Send me your email.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.