1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | #include <stdio.h> #include <iostream> #include <iomanip> #include <math.h> using namespace std; double drag_co(const double& drag, const double& air_density, const double& velocity, const double& area); double drag(const double& drag_co, const double& air_density, const double& velocity, const double& area); int main(void) { #define ROWS 3 #define COLS 4 double data[ROWS][COLS]; // data[row][col] register int row, col; // generic index for 2D-array register int rows = sizeof(data) / sizeof(data[0]); register int cols = sizeof(data[0]) / sizeof(data[0][0]); // file opened FILE* fin = fopen("[0] data.txt", "r"); if(!fin) return -1; cout << endl << endl; // 차수 [1:3]에 대한 항력계수 계산 및 출력 double DRAG_co[3]; for (row = 0; row < rows; ++row) { for (col = 0; col < cols; ++col) { fscanf(fin, "%lf", &data[row][col]); register int offset = col % cols; if (offset == cols - 1) // 기준면적 { DRAG_co[row] = drag_co( // 항력계수 data[row][col - 3], data[row][col - 2], data[row][col - 1], data[row][col]); printf("%.0lf ", data[row][col]); cout << "\tdrag_co : "; printf("%le", DRAG_co[row]); cout << endl; } else if (offset == cols - 2) printf("%.0lf ", data[row][col]); // 속도 else if (offset == cols - 3) printf("%.0le ", data[row][col]); // 밀도 else if (offset == 0) printf("%.0lf ", data[row][col]); // 항력 } } cout << endl << endl; fclose(fin); // 기준면적[4:14] ++2 // 속도[90:400] ++10 // 속도 [1:200] / [201:300] / [301:400] // 공기밀도 고정 register int area, velocity, label = 1; double density = 0.000001, DRAG_CO, DRAG, DRAG_CO_2nd; FILE* fout = fopen("[0] data_out.txt", "w"); if (!fout) return -1; for (area = 4; area <= 14; area += 2) { for (velocity = 90; velocity <= 400; velocity += 10) { if (velocity >= 1 && velocity <= 200) DRAG_CO = DRAG_co[0]; else if (velocity >= 201 && velocity <= 300) DRAG_CO = DRAG_co[1]; else if (velocity >= 301 && velocity <= 400) DRAG_CO = DRAG_co[2]; DRAG = drag(DRAG_CO, density, velocity, area); DRAG_CO_2nd = drag_co(DRAG, density, velocity, area); cout << setw(5) << setfill(' ') << label++ << setw(10) << setfill(' ') << area << setw(10) << setfill(' ') << velocity; printf("\t%.0le\t%.4le\n", density, DRAG_CO_2nd); fprintf(fout, "%5d%10d%10d\t%.0le\t%.4le\n", label-1, area, velocity, density, DRAG_CO_2nd); } } fclose(fout); return 0; } double drag_co(const double& drag, const double& air_density, const double& velocity, const double& area) { // Cd = drag / (PV^2 * A /2) double drag_co = drag / ((air_density * pow(velocity, 2) * area) / 2); return drag_co; } double drag(const double& drag_co, const double& air_density, const double& velocity, const double& area) { // drag = Cd * (PV^2 * A /2) double drag = drag_co * ((air_density * pow(velocity, 2) * area) / 2); return drag; } | cs |
12/12/2015
Temporary
피드 구독하기:
댓글 (Atom)
댓글 없음:
댓글 쓰기