Ejemplo n.º 1
0
Archivo: A3.cpp Proyecto: nMerlin/CP
//Funktion nimmt gewünschte Anfangsbedingungen und erstellt passende Plots für Aufgabe 3c
void A3c(std::vector<double> y, std::string name, double h) {
	int N = ceil(100/h);
	std::vector<double> LR;

	std::ofstream a3_r(("./" + name + "_r.dat").c_str());
	std::ofstream a3_LR_x(("./" + name + "_LR_x.dat").c_str());
	std::ofstream a3_LR_y(("./" + name + "_LR_y.dat").c_str());
	std::ofstream a3_LR_z(("./" + name + "_LR_z.dat").c_str());
	std::ofstream a3_LR(("./" + name + "_LR.dat").c_str());
	
	for (int i = 0; i < N; i++) {
		y = Runge_Kutta(&F2,y,h,h*i);
		
		LR = LenzRunge(y);
		
		a3_r << y[0] << " " << y[1] << " " << y[2] << std::endl;
		a3_LR_x << i*h << " " << LR[0] << std::endl;
		a3_LR_y << i*h << " " << LR[1] << std::endl;
		a3_LR_z << i*h << " " << LR[2] << std::endl;
		a3_LR << 0 << " " << 0 << " " << 0 << " " << LR[0] << " " << LR[1] << " " << LR[2] << std::endl;
	}
	
	a3_r.close();
	a3_LR_x.close();
	a3_LR_y.close();
	a3_LR_z.close();
	a3_LR.close();
	
	//plot3d("./",name+"_r");
	//plot("./",name+"_LR_x");
	//plot("./",name+"_LR_y");
	//plot("./",name+"_LR_z");
	plot3d("./",name+"_r");
}
Ejemplo n.º 2
0
int main(void)
{
	double a;
	double x0, *y0, l;
	int cnt, n;
	scanf("%lf", &x0);
	scanf("%d", &cnt);
	y0 = malloc(cnt * sizeof(double));
	double *y0q = malloc(cnt * sizeof(double));
	func = malloc(cnt * sizeof(double));
	int i;
	for (i = 0; i < cnt; i++)
	{
		scanf("%lf", &y0[i]);
	}
	memcpy(y0q, y0, cnt * sizeof(double));
	scanf("%lf", &l);
	scanf("%d", &n);
	scanf("%lf", &a);
	deffunc();
	puts("Метод Рунге-Кутта второго порядка\n");
	Runge_Kutta(x0, y0, cnt, l, a, n);
	puts("--------");
	puts("Метод Рунге-Кутта четвертого порядка\n");
	Runge_Kutta4(x0, y0q, cnt, l, n);
	return 0;
}
Ejemplo n.º 3
0
Archivo: A3.cpp Proyecto: nMerlin/CP
//Funktion nimmt gewünschte Anfangsbedingungen und erstellt passende Plots für Aufgabe 2a
void A3a(std::vector<double> y, std::string name, double h) {
	int N = ceil(100/h);
	//int size_y = y.size();
	std::ofstream a3_r(("./" + name + "_r.dat").c_str());
	
	for (int i = 0; i < N; i++) {
		y = Runge_Kutta(&F2,y,h,h*i);
		a3_r << y[0] << " " << y[1] << " " << y[2] << std::endl;
	}
	
	a3_r.close();
	
	plot3d("./",name+"_r");
}
Ejemplo n.º 4
0
Archivo: A1.cpp Proyecto: nMerlin/CP
//Aufgabe 1 a.)
void A1a(std::vector<double> y, std::string name, double h) {
	int N = ceil(50/h);
	double Eges;

	std::ofstream a1_Eges(("./" + name + "_Eges.dat").c_str());
	
	for (int i = 0; i < N; i++) {
		y = Runge_Kutta(bind(&Pendel_a,std::placeholders::_1,std::placeholders::_2,1,0,0,0),y,h,h*i);
		Eges = y[0] * y[0] + y[1] * y[1]; //Energieerhaltung bei harmonischem Oszillator
		
		a1_Eges << h*i << " " << Eges << std::endl;
	}
	
	a1_Eges.close();
	
	plot("./",name+"_Eges");
}
Ejemplo n.º 5
0
Archivo: A1.cpp Proyecto: nMerlin/CP
//Aufgabe 1 b.)
void A1b(std::vector<double> y, std::string name, double h) {
	int N = ceil(50./h);
	double theta_pi, theta_punkt;
	double A = 1.5, omega = 2./3., c=1.;
	double Q = 1.;

	std::ofstream a2_praum(("./" + name + "_Phasenraum.dat").c_str());
	
	for (int i = 0; i < N; i++) {
		y = Runge_Kutta(bind(&Pendel_a,std::placeholders::_1,std::placeholders::_2,Q,A,omega,c),y,h,h*i);
		theta_pi = y[0]/M_PI;
		theta_punkt = y[1];
		
		if (i%100 == 0) {
			a2_praum << theta_pi << " " << theta_punkt << std::endl;
		}
	}
	
	a2_praum.close();
	
	plot("./",name+"_Phasenraum");
}
Ejemplo n.º 6
0
Archivo: A3.cpp Proyecto: nMerlin/CP
//Erwartet mit y geeignete 3D-Anfangsbedingungen und erstellt Plots für Energie und Drehimpuls
void A3b(std::vector<double> y, std::string name, double h) {
	int N = ceil(100/h);	//100 ist die Gesamtzeit
	double E_kin, E_pot, E_ges;
	double _L;
	//int size_y = y.size();
	std::ofstream a3_r(("./" + name + "_r.dat").c_str());
	std::ofstream a3_ekin(("./" + name + "_ekin.dat").c_str());
	std::ofstream a3_epot(("./" + name + "_epot.dat").c_str());
	std::ofstream a3_eges(("./" + name + "_eges.dat").c_str());
	std::ofstream a3_L(("./" + name + "_L.dat").c_str());
	
	for (int i = 0; i < N; i++) {
		y = Runge_Kutta(&F2,y,h,h*i);
		E_kin = 0.5*(y[3]*y[3]+y[4]*y[4]+y[5]*y[5]);
		E_pot = -1/sqrt(y[0]*y[0]+y[1]*y[1]+y[2]*y[2]);
		E_ges = E_kin + E_pot;
		_L = betrag(L(y));
		a3_r << y[0] << " " << y[1] << " " << y[2] << std::endl;
		a3_ekin << h*i << " " << E_kin << std::endl;
		a3_epot << h*i << " " << E_pot << std::endl;
		a3_eges << h*i << " " << E_ges << std::endl;
		a3_L << h*i << " " << _L << std::endl;
	}
	
	a3_r.close();
	a3_ekin.close();
	a3_epot.close();
	a3_eges.close();
	a3_L.close();
	
	plot3d("./",name+"_r");
	plot("./",name+"_ekin");
	plot("./",name+"_epot");
	plot("./",name+"_eges");
	plot("./",name+"_L");
}