Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F102859096
ForwardEulerSolver.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Feb 24, 22:40
Size
759 B
Mime Type
text/x-c
Expires
Wed, Feb 26, 22:40 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
24443499
Attached To
R1106 Programming Concept Rouaze
ForwardEulerSolver.cpp
View Options
/*
* ForwardEulerSolver.cpp
*
* Created on: Oct 25, 2012
* Author: rpopescu
*/
#include "ForwardEulerSolver.hpp"
#include <cmath>
ForwardEulerSolver::ForwardEulerSolver()
{}
ForwardEulerSolver::~ForwardEulerSolver()
{}
void ForwardEulerSolver::SolveEquation(std::ostream& stream)
{
double y_prev = GetInitialValue();
double y_next;
double t_prev = GetInitialTime();
double t_next;
double h = GetStepSize();
int n = static_cast<int>(
std::floor((GetFinalTime() - GetInitialTime()) / h));
stream << t_prev << " " << y_prev << "\n";
for (int i = 1; i <= n; ++i) {
y_next = y_prev + h * RightHandSide(y_prev, t_prev);
t_next = t_prev + h;
stream << t_next << " " << y_next << "\n";
y_prev = y_next;
t_prev = t_next;
}
}
Event Timeline
Log In to Comment