//
//Jonathan Klaasen
//Lab 2 part 2
//
//This program solves the state equations for the system provided
//It uses the Euler's method of solving differential equations
//


#include <stdio.h>
#include <math.h>

int main (void)
{
	double Kd1, Kd2, Kd3, Ks1, Ks2, Ks3, h, M1, M2, F, x1, x2, vf1, vf2, t1, t2, v1_last, v2_last, x1_last, x2_last;
	
	
	
	printf("Enter value for Kd1   ");
	scanf("%lf", &Kd1);
	printf("Enter value for Kd2   ");
	scanf("%lf", &Kd2);
	printf("Enter value for Kd3   ");
	scanf("%lf", &Kd3);
	printf("Enter value for Ks1   ");
	scanf("%lf", &Ks1);
	printf("Enter value for Ks2   ");
	scanf("%lf", &Ks2);
	printf("Enter value for Ks3   ");
	scanf("%lf", &Ks3);
	printf("Enter value for M1   ");
	scanf("%lf", &M1);
	printf("Enter value for M2   ");
	scanf("%lf", &M2);
	printf("Enter value for x01   ");
	scanf("%lf", &x1);
	printf("Enter value for x02   ");
	scanf("%lf", &x2);
	printf("Enter value for v01   ");
	scanf("%lf", &vf1);
	printf("Enter value for v02   ");
	scanf("%lf", &vf2);
	printf("Enter value for F   ");
	scanf("%lf", &F);
	printf("Enter value for step size, h   ");
	scanf("%lf", &h);
	printf("Enter value for beginning time, t1   ");
	scanf("%lf", &t1);
	printf("Enter value for ending time, t2   ");
	scanf("%lf", &t2);

	printf("t = %.4lf  v01 = %.4lf   v02 = %.4lf \n", t1, vf1, vf2);
	t1+=h;

	while (t1 <= t2)
	{
		v1_last = vf1;
		v2_last = vf2;
		x1_last = x1;
		x2_last = x2;
		
		x1 = x1_last + h * v1_last;
		x2 = x2_last + h * v2_last;

		vf1 = (h * ((((-Ks1 - Ks2)/M1) * x1_last) + ((Ks2/M1) * x2_last) + (((-Kd1 - Kd2)/M1) * v1_last) + ((Kd2/M1) * v2_last))) + v1_last;
		vf2 = (h * (((Ks2/M2) * x1_last) + (((-Ks2 - Ks3)/M2) * x2_last) + ((Kd2/M2) * v1_last) + (((-Kd2 - Kd3)/M2) * v2_last) + (F/M2))) + v2_last;
	
	printf("t = %.4lf  v01 = %.4lf   v02 = %.4lf \n", t1, vf1, vf2);
		t1+=h;
	}
	
	return 0;
}
	
