Last active
June 24, 2017 10:46
-
-
Save lefirea/76bcd29abae93510d8b62b94d5b2769f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<math.h> | |
#define PI 3.141592653589793 | |
#define R0 100.0 | |
#define X0 100.0 | |
#define E 100.0 | |
#define SIZE 81 | |
double power[SIZE][SIZE]; | |
double pmin, pmax; | |
double rmin, rmax, rdiv; | |
double xmin, xmax, xdiv; | |
int nr, nx, ndiv; | |
void input(); | |
void keisan(); | |
void graph(); | |
int main(void) { | |
input(); | |
keisan(); | |
graph(); | |
return 0; | |
} | |
void input() { | |
printf("rmin? ->"); | |
scanf("%lf", &rmin); | |
printf("rmax? ->"); | |
scanf("%lf", &rmax); | |
printf("nr? ->"); | |
scanf("%d", &nr); | |
printf("xmin? ->"); | |
scanf("%lf", &xmin); | |
printf("xmax? ->"); | |
scanf("%lf", &xmax); | |
printf("nx? ->"); | |
scanf("%d", &nx); | |
printf("ndiv? ->"); | |
scanf("%lf", &ndiv); | |
} | |
void keisan() { | |
int i=0, j=0; | |
double r, x; | |
double rm, xm; | |
rm = rmax - rmin; | |
xm = xmax - xmin; | |
for (x = xmin; x <= xmax; x+=(xm/nx)) { | |
for (r = rmin; r <= rmax; r+=(rm/nr)) { | |
power[i][j] = ((E*E)*r) / (pow(R0+r,2) + pow(X0+x,2)); | |
if (i == 0) { pmax = power[i][j]; pmin = power[i][j]; } | |
else { | |
if (power[i][j] < pmin) { pmin = power[i][j]; } | |
if (power[i][j] > pmax) { pmax = power[i][j]; } | |
} | |
j++; | |
} | |
j = 0; | |
i++; | |
} | |
} | |
void graph() { | |
int i, j; | |
char letter[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | |
int idx; | |
/* | |
for (i = 0;i < nx;++i) { | |
if (i % 5 == 0) { printf("5.0f", (rmax / (nr - 1))*i); } | |
} | |
for (i = 0;i < nr;++i) { | |
if (i % 5 == 0) { printf("+"); } | |
else { printf("-"); } | |
} | |
printf("--->\n"); | |
for (j = 0;j < nx;++j) { | |
if (j % 5 == 0) { printf("5.0f"), (rmin / (nr - 1)*j); } | |
}*/ | |
for (i = 0;i < nr;++i) { | |
for (j = 0;j < nx;++j) { | |
idx = int(power[i][j]); | |
printf("%c", letter[idx]); | |
} | |
printf("\n"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment