50% found this document useful (2 votes)
652 views

Euler Modified Method C++

This program uses Modified Euler's Method to solve differential equations. It takes initial values for x and y from the user, along with the final value of x and the step size. It then iteratively calculates updated y values over multiple iterations to approach the solution, outputting the results at each step. Finally, it displays the calculated y value at the end point x value provided by the user.

Uploaded by

Akshay Bora
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
50% found this document useful (2 votes)
652 views

Euler Modified Method C++

This program uses Modified Euler's Method to solve differential equations. It takes initial values for x and y from the user, along with the final value of x and the step size. It then iteratively calculates updated y values over multiple iterations to approach the solution, outputting the results at each step. Finally, it displays the calculated y value at the end point x value provided by the user.

Uploaded by

Akshay Bora
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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