Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F102854620
RungeKuttaSolver.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, 21:34
Size
997 B
Mime Type
text/x-c
Expires
Wed, Feb 26, 21:34 (2 d)
Engine
blob
Format
Raw Data
Handle
24442313
Attached To
R1106 Programming Concept Rouaze
RungeKuttaSolver.cpp
View Options
/*
* RungeKuttaSolver.cpp
*
* Created on: Oct 25, 2012
* Author: rpopescu
*/
#include "RungeKuttaSolver.hpp"
#include <cmath>
RungeKuttaSolver::RungeKuttaSolver()
{}
RungeKuttaSolver::~RungeKuttaSolver()
{}
void RungeKuttaSolver::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) {
double k1 = h * RightHandSide(y_prev, t_prev);
double k2 = h * RightHandSide(y_prev + 0.5 * k1, t_prev + 0.5 * h);
double k3 = h * RightHandSide(y_prev + 0.5 * k2, t_prev + 0.5 * h);
double k4 = h * RightHandSide(y_prev + k3, t_prev + h);
y_next = y_prev + 1.0/6.0 * (k1 + 2 * k2 + 2 * k3 + k4);
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