/* Eulers method implementation in CPP Language----- Md. Alamgir Hossain Department of Computer Science & Engineering. Jessore University of Science & Technology, Bangladesh. Email : alamgir.cse14.just@gmail.com */ #include<bits/stdc++.h> using namespace std; float equation(float x, float y) { ///Here enter the right side of your differential equation--- ///Some example of equation in the res variable-- ///You can check with your desired equation ///From here remove comment and check for another equation... float res; ///Equation start // res = (3*x*x)+1; res = (x*x)+(y*y); // res = y+(x*x); // res = ((2*y)/x)+(x*x*x); //res = y-((2*x)/y); return res; } ///Main function start from here---- int main() { float x0; cout<<"Enter the value of X0 : "; cin>>x0; float y0; cout<<"Enter the value of Y0 : "; cin>>y0; float xn; cout<<"Enter the value of Xn or x1 : "; cin>>xn; char pr; cout<<"If you want to enter the value of h press 1 else other : "; cin>>pr; float x1 = 0.0, h, h2; if(pr == '1'){ cout<<"Enter the value of h : "; cin>>h2; h = h2; }else{ h = xn - x0; } float y1,y2; x1 = h + x0; y1 = y0 + (h * equation(x0, y0)); y2 = y1 + (h * equation(x1, y1)); ///Now we want to check Eulers/Eulers Modified/Eulers Improved method-- cout<<"Press 1 for Eulers method, 2 for Modified and 3 for Improved method--"; char p; cin>>p; ///Machanism start for Eulers Method---------- if(p == '1'){ cout<<"Press 2 for two values 1 for one values"; char pp; if(pp == '2'){ cout<<"Enter the second value of x : "; float x2; cin>>x2; cout<<"\nThe Result for Y1("<<xn<<") using Eulers method is : "<<y1<<"\n"; cout<<"\nThe Result for Y2("<<x2<<") using Eulers method is : "<<y2<<"\n"; } else if(pp == '1'){ cout<<"\nThe Result for Y1("<<xn<<") using Eulers method is : "<<y1<<"\n"; } else{ cout<<"Please enter valid value---\n"; return 0; } } ///Eulers modified method start---------- else if(p == '2') { float v,v1,v2,v11,v21,vv; v1 = x0 + (h/2); v2 = y0 + ((h/2)+equation(x0,y0)); v = (h*(equation(v1,v2))+y0); v11 = x1 + (h/2); v21 = v + ((h/2)*equation(x1,v)); vv = (h * (equation(v11,v21))) + v; cout<<"Press 2 for two values 1 for one values"; char pp; cin>>pp; if(pp=='2'){ cout<<"Enter the second value of x : "; float x2; cin>>x2; cout<<"\nThe Result for Y1("<<xn<<") using Eulers modified method is : "<<v<<"\n"; cout<<"\nThe Result for Y2("<<x2<<") using Eulers modified method is : "<<vv<<"\n"; } else if(pp=='1'){ cout<<"\nThe Result for Y1("<<xn<<") using Eulers Modified method is : "<<v<<"\n"; } else{ cout<<"\nPlease enter valid value---\n"; return 0; } } ///Mechanism for Improved Eulers Method is------ else if(p == '3'){ float y1,y2; y1 = y0 + (h/2) * ((equation(x0,y0)) + (equation((x0+h),(y0+(h*(equation(x0,y0))))))); y2 = y1 + (h/2) * ((equation(x1,y1)) + (equation((x1+h),(y1+(h*(equation(x1,y1))))))); cout<<"Press 2 for two values 1 for one values"; char pp; cin>>pp; if(pp=='2'){ cout<<"Enter the second value of x : "; float x2; cin>>x2; cout<<"\nThe Result for Y1("<<xn<<") using Improved Eulers method is : "<<y1<<"\n"; cout<<"\nThe Result for Y2("<<x2<<") using Improved Eulers method is : "<<y2<<"\n"; } else if(pp=='1'){ cout<<"\nThe Result for Y1("<<xn<<") using Improved Eulers Modified is : "<<y1<<"\n"; } else{ cout<<"Please enter valid value---\n"; return 0; } } cout<<"\n\nThank You!!!!!\n\n"; return 0; } ///Input/Output Example----------------- /* Enter the value of X0 : 0 Enter the value of Y0 : 1 Enter the value of Xn : .1 If you want to enter the value of h press 1 else other : 1 Enter the value of h : .1 Press 1 for Eulers method, 2 for Modified and 3 for Improved method--2 Press 2 for two values 1 for one values2 Enter the second value of x : .2 The Result for Y1(0.1) using Eulers modified method is : 1.4205 The Result for Y2(0.2) using Eulers modified method is : 1.65437 Thank You!!!!! */
Eulers Method, Eulers Modified and Eulers Improved method implementation in CPP language
Click any Bellow Tabs/Tags
Alamgir-Hossain
(14)
Algorithms
(5)
Android problem
(2)
ANN
(1)
ArticleWriting
(26)
Artificial Intelligence
(1)
Assembly
(1)
Bangla Love Poem
(3)
Bangla Poem
(2)
best programming solution
(9)
Books
(2)
BUET IICT MSC Admission
-2021
(1)
C
(49)
Campus
(7)
CPP
(88)
Database
(4)
Differences
(2)
Fishing
(1)
HSC
(1)
Html
(4)
interesting programming solution
(9)
Interview
(2)
It job preparation
(7)
JAVA
(97)
JavaScript
(5)
JSON
(1)
lead generation
(1)
machine learning
(2)
ML Projects
(3)
NewsPaper
(19)
Others
(13)
Perl
(23)
Php
(4)
Poem
(4)
Presentation
(1)
ProblemSolving
(3)
Project
(21)
Prolog
(13)
Python
(33)
research
(18)
Research Tool
(1)
Security
(3)
Social Engineering
(1)
Testimonials
(5)
Tutorial
(2)
Writings
(15)
XML
(1)
YoutubeSEO
(1)
উক্তি
(1)
কবিতা-আলগীর হোসেন
(2)
লেখনী
(33)
LATEST
3-latest-65px
Popular Posts
-
All instructions for connection & insert data in mysql from java JSP and Servlet using tomcat serverFrom this tutorial you can learn about... All instructions for connection & insert data in mysql from java JSP and Servlet using tomc...
-
% Prolog program for addition and multplication-------- % Alamgir Hossain % CSE, JUST go :- write ( 'Enter first number : ' ...
-
Inverse Lagrange’s Interpolation Formula Theory : . Example : 1. Use Lagrange’s inverse interpolation fo...
-
Project Name : Online examination system. Framework : MVC framework in java(3 layer architecture). Language: JAVA JSP, SERVLET, JS...
-
Here is the source code for online exam system using PHP, MYSQL,AJAX, JAVASCRIPT etc.... Source code for Online Exam System
No comments:
Post a Comment