Insights Blog
-- Browse All Articles --
Physics Articles
Physics Tutorials
Physics Guides
Physics FAQ
Math Articles
Math Tutorials
Math Guides
Math FAQ
Education Articles
Education Guides
Bio/Chem Articles
Technology Guides
Computer Science Tutorials
Forums
Intro Physics Homework Help
Advanced Physics Homework Help
Precalculus Homework Help
Calculus Homework Help
Bio/Chem Homework Help
Engineering Homework Help
Trending
Featured Threads
Log in
Register
What's new
Search
Search
Search titles only
By:
Intro Physics Homework Help
Advanced Physics Homework Help
Precalculus Homework Help
Calculus Homework Help
Bio/Chem Homework Help
Engineering Homework Help
Menu
Log in
Register
Navigation
More options
Contact us
Close Menu
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Forums
Homework Help
Engineering and Comp Sci Homework Help
Solve Euler Method in C++ for Beginners
Reply to thread
Message
[QUOTE="Mark44, post: 6641121, member: 147785"] With a minor change in the for loop in your code I was able to get it to work. You have a variable named slope that you didn't use. Your function f [U]is[/U] the slope. The example differential equation I'm solving is dy/dx = 2x + 0y, so f(x, y) = 2x + 0y, or f(x, 0). Here is my definition for f: [code=c++]double f(double x, double y) { return 2 * x ; }[/code] Since y doesn't appear in the return value, this function is called using f(x, 0). Here is my for loop: [code=c++] for (i = 0; i < n; i++) { slope = f(x0, 0); yn = y0 + h * slope; cout << x0 << "\t" << y0 << "\t" << slope << "\t" << yn << endl; y0 = yn; x0 = x0 + h; }[/code] Using dy/dx = 2x and a starting point of (1, 1), and an ending x-value of 1.1 and 10 steps, I get a y-value of 1.209, which is pretty close to the exact value of 1.21. Euler's method is probably the least accurate of methods for solving differential equations, so my result isn't so far off. [/QUOTE]
Insert quotes…
Post reply
Forums
Homework Help
Engineering and Comp Sci Homework Help
Solve Euler Method in C++ for Beginners
Back
Top