0% found this document useful (0 votes)
16 views1 page

Euler

This document describes a C++ program that uses the Euler method to numerically solve a first-order ordinary differential equation. The program takes initial values for x and y, calculates the slope at each step using a defined function, and outputs the updated x and y values until it reaches the specified xn point.

Uploaded by

Aronyak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views1 page

Euler

This document describes a C++ program that uses the Euler method to numerically solve a first-order ordinary differential equation. The program takes initial values for x and y, calculates the slope at each step using a defined function, and outputs the updated x and y values until it reaches the specified xn point.

Uploaded by

Aronyak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include<iostream>

#define f(x,y) -2*x*y*y;

using namespace std;

int main()
{
float x0, y0, xn, h, yn, slope;
int i, n;

cout<<"Enter Initial Condition"<< endl;


cout<<"x0 = ";
cin>> x0;
cout<<"y0 = ";
cin >> y0;
cout<<"Enter calculation point xn = ";
cin>>xn;
cout<<"Enter number of steps: ";
cin>> n;

h = (xn-x0)/n;

cout<<"\nx0\ty0\tslope\tyn\n";
cout<<"------------------------------\n";

for(i=0; i < n; i++)


{
slope = f(x0, y0);
yn = y0 + h * slope;
cout<< x0<<"\t"<< y0<<"\t"<< slope<<"\t"<< yn<< endl;
y0 = yn;
x0 = x0+h;
}

cout<<"\nValue of y at x = "<< xn<< " is " << yn;

return 0;
}

You might also like