main () { int x,y, poziom, pion; float t; printf("\nWYKRES FUNKCJI:\n\n "); for (x=0; x<szer; x=x+1) for (y=0; y<wys; y=y+1) rysuj(x, y, ' '); pion = interpoluj(0, dol_x, gora_x, szer); for(y=0; y<wys; y=y+1) rysuj(pion, y, '|'); poziom = interpoluj(0, dol_y, gora_y, wys); for(x=0; x<szer; x=x+1) rysuj(x, poziom, '-'); rysuj(pion, poziom, '+'); for (t=srodek; t<zakres; t=t+skok) rysuj(f_x(t), f_y(t), '*'); for (y=wys-1; y>=0; y=y-1) { for (x=0; x<szer; x=x+1) printf("%c", rysunek[x][y]); printf("\n "); } printf("\n\n"); }
double x_force(int index) { double f = 0.0; int i = 0; for(i = 0; i < 2; i++ ) { if(i == index) continue; f += f_x(&bodies[index], &bodies[i]); } return f; }
int lorentz(int times, double step) { double x = 5; double y = 20; double z = -10; FILE* fp; fp = fopen("data/lorentz.csv","w+"); for (int i = 0; i < times; i++) { x += step * f_x(x,y); y += step * f_y(x,y,z); z += step * f_z(x,y,z); fprintf(fp,"%lf,%lf,%lf\n",x,y,z); } fclose(fp); return 0; }
void NumericalFlux::riemann_solver(double result[4], double w_l[4], double w_r[4]) { //printf("w_l: %f %f %f %f\n", w_l[0], w_l[1], w_l[2], w_l[3]); //printf("w_r: %f %f %f %f\n", w_r[0], w_r[1], w_r[2], w_r[3]); double _tmp1[4][4]; double _tmp2[4][4]; double _tmp3[4]; double _tmp4[4]; A_minus(_tmp1, w_r[0], w_r[1], w_r[2], w_r[3]); A_minus(_tmp2, w_l[0], w_l[1], w_l[2], w_l[3]); dot_vector(_tmp3, _tmp1, w_r); dot_vector(_tmp4, _tmp2, w_l); for (int i=0; i < 4; i++) { double _1 = f_x(i, w_l[0], w_l[1], w_l[2], w_l[3]); double _2 = _tmp3[i]; double _3 = _tmp4[i]; result[i] = _1 + _2 - _3; } }
void OdeGear( Fun &F , size_t m , size_t n , const Vector &T , Vector &X , Vector &e ) { // temporary indices size_t i, j, k; typedef typename Vector::value_type Scalar; // check numeric type specifications CheckNumericType<Scalar>(); // check simple vector class specifications CheckSimpleVector<Scalar, Vector>(); CPPAD_ASSERT_KNOWN( m >= 1, "OdeGear: m is less than one" ); CPPAD_ASSERT_KNOWN( n > 0, "OdeGear: n is equal to zero" ); CPPAD_ASSERT_KNOWN( size_t(T.size()) >= (m+1), "OdeGear: size of T is not greater than or equal (m+1)" ); CPPAD_ASSERT_KNOWN( size_t(X.size()) >= (m+1) * n, "OdeGear: size of X is not greater than or equal (m+1) * n" ); for(j = 0; j < m; j++) CPPAD_ASSERT_KNOWN( T[j] < T[j+1], "OdeGear: the array T is not monotone increasing" ); // some constants Scalar zero(0); Scalar one(1); // vectors required by method Vector alpha(m + 1); Vector beta(m + 1); Vector f(n); Vector f_x(n * n); Vector x_m0(n); Vector x_m(n); Vector b(n); Vector A(n * n); // compute alpha[m] alpha[m] = zero; for(k = 0; k < m; k++) alpha[m] += one / (T[m] - T[k]); // compute beta[m-1] beta[m-1] = one / (T[m-1] - T[m]); for(k = 0; k < m-1; k++) beta[m-1] += one / (T[m-1] - T[k]); // compute other components of alpha for(j = 0; j < m; j++) { // compute alpha[j] alpha[j] = one / (T[j] - T[m]); for(k = 0; k < m; k++) { if( k != j ) { alpha[j] *= (T[m] - T[k]); alpha[j] /= (T[j] - T[k]); } } } // compute other components of beta for(j = 0; j <= m; j++) { if( j != m-1 ) { // compute beta[j] beta[j] = one / (T[j] - T[m-1]); for(k = 0; k <= m; k++) { if( k != j && k != m-1 ) { beta[j] *= (T[m-1] - T[k]); beta[j] /= (T[j] - T[k]); } } } } // evaluate f(T[m-1], x_{m-1} ) for(i = 0; i < n; i++) x_m[i] = X[(m-1) * n + i]; F.Ode(T[m-1], x_m, f); // solve for x_m^0 for(i = 0; i < n; i++) { x_m[i] = f[i]; for(j = 0; j < m; j++) x_m[i] -= beta[j] * X[j * n + i]; x_m[i] /= beta[m]; } x_m0 = x_m; // evaluate partial w.r.t x of f(T[m], x_m^0) F.Ode_dep(T[m], x_m, f_x); // compute the matrix A = ( alpha[m] * I - f_x ) for(i = 0; i < n; i++) { for(j = 0; j < n; j++) A[i * n + j] = - f_x[i * n + j]; A[i * n + i] += alpha[m]; } // LU factor (and overwrite) the matrix A int sign; CppAD::vector<size_t> ip(n) , jp(n); sign = LuFactor(ip, jp, A); CPPAD_ASSERT_KNOWN( sign != 0, "OdeGear: step size is to large" ); // Iterations of Newton's method for(k = 0; k < 3; k++) { // only evaluate f( T[m] , x_m ) keep f_x during iteration F.Ode(T[m], x_m, f); // b = f + f_x x_m - alpha[0] x_0 - ... - alpha[m-1] x_{m-1} for(i = 0; i < n; i++) { b[i] = f[i]; for(j = 0; j < n; j++) b[i] -= f_x[i * n + j] * x_m[j]; for(j = 0; j < m; j++) b[i] -= alpha[j] * X[ j * n + i ]; } LuInvert(ip, jp, A, b); x_m = b; } // return estimate for x( t[k] ) and the estimated error bound for(i = 0; i < n; i++) { X[m * n + i] = x_m[i]; e[i] = x_m[i] - x_m0[i]; if( e[i] < zero ) e[i] = - e[i]; } }