[C++] Euler-Cromer Method - Muhammad Faruq Nuruddinsyah
[C++] Euler-Cromer Method

Here's Euler-Cromer Method implementation in C++

Source Code:
/*
* File: euler-cromer.cpp
* Author: Muhammad Faruq Nuruddinsyah
*
* Created on October 27, 2015, 9:26 PM
*/
 
 
#include <iostream>
#include <fstream>
 
using namespace std;
 
int main(){
	float xn, xn_1, vn, vn_1;
	float k = 1.0, m = 1.0, dt = 0.001;
 
	ofstream file;
	file.open("euler-cromer.dat");
 
	xn_1 = 1.0;
	vn_1 = 0.0;
	xn = 1.0;
	vn = 0.0;
 
	for(int i = 0; i < 10000; i++){
		xn = xn_1 + vn * dt;
		vn = vn_1 - ((k * xn) * dt) / m;
 
		file << xn << "\t" << vn << endl;
 
		xn_1 = xn;
		vn_1 = vn;
	}
 
	file.close();
	return 0;
}

Informasi:
Lihat semua daftar ACS - Download: euler-cromer.cpp - Tanggal: 27 Oktober 2015 - Kategori: C++