每行maxX从minY开始,反之亦然 这使得双曲线的一部分可以适合每个交点标记的单个矢量的近似值。 一般如何将这些向量求和以得出弓长?
代码给出了错误的结果-为什么x和y的曲率关系为
#include <stdio.h>
#include <stdlib.h>
double sqrt1(double a);
double powerOfTen(int num);
double func_relDREF();
double _sin(double x);
double _cos(double x);
double _tan(double x);
double func_pow2(double v);
double func_cot(double rad);
int _fact(int a);
int main() {
double a = 1.0;
double b = 1.0;
double phi = 1000;
double DREF = 2*func_cot(phi/2.0);
double A = (a*b);
double res = 2.0*(((sqrt1(func_pow2(2.0*A)+sqrt1(func_pow2(A))))*A)/sqrt1(func_pow2(3.0*A)+(sqrt1(func_pow2(A)))));
double bow = res * DREF;
fprintf(stdout, "%f :: %f", res , bow);
return 0;
}
int _fact (int a)
{
if (a>1) // Base case = 1
{
return (a * _fact(a-1)); // fact(a-1) is the recursive call in this step to call its own function again
}
else // If the value of the a = 1, then simply return the same
return 1;
}
double func_cot(double rad) {
double res = 0.0;
res = 1/_tan(rad);
return res;
}
double _sin(double x) {
double y = x;
double s = -1;
int i = 0;
for (i=3; i<=10; i+=2) {
y+=s*(powerOfTen((x,i)/_fact(i)));
s *= -1;
}
return y;
}
double _cos(double x) {
double y = 1;
double s = -1;
int i = 0;
for (i=2; i<=10; i+=2) {
y+=s*(powerOfTen((x,i)/_fact(i)));
s *= -1;
}
return y;
}
double _tan(double x) {
return (_sin(x)/_cos(x));
}
double func_relDREF() {
return (3.141592653589793 / 2.0) / sqrt1(2.0);
}
double func_pow2(double v) {
return v*v;
}
double powerOfTen(int num){
double rst = 1.0;
int i = 0;
if(num >= 0){
for(i = 0; i < num ; i++){
rst *= 10.0;
}
}else{
for(i = 0; i < (0 - num ); i++){
rst *= 0.1;
}
}
return rst;
}
double sqrt1(double a)
{
/*
find more detail of this method on wiki methods_of_computing_square_roots
*** Babylonian method cannot get exact zero but approximately value of the square_root
*/
double z = a;
double rst = 0.0;
int max = 8; // to define maximum digit
int i;
double j = 1.0;
for(i = max ; i > 0 ; i--){
// value must be bigger then 0
if(z - (( 2 * rst ) + ( j * powerOfTen(i)))*( j * powerOfTen(i)) >= 0)
{
while( z - (( 2 * rst ) + ( j * powerOfTen(i)))*( j * powerOfTen(i)) >= 0)
{
j++;
if(j >= 10) break;
}
j--; //correct the extra value by minus one to j
z -= (( 2 * rst ) + ( j * powerOfTen(i)))*( j * powerOfTen(i)); //find value of z
rst += j * powerOfTen(i); // find sum of a
j = 1.0;
}
}
for(i = 0 ; i >= 0 - max ; i--){
if(z - (( 2 * rst ) + ( j * powerOfTen(i)))*( j * powerOfTen(i)) >= 0)
{
while( z - (( 2 * rst ) + ( j * powerOfTen(i)))*( j * powerOfTen(i)) >= 0)
{
j++;
}
j--;
z -= (( 2 * rst ) + ( j * powerOfTen(i)))*( j * powerOfTen(i)); //find value of z
rst += j * powerOfTen(i); // find sum of a
j = 1.0;
}
}
// find the number on each digit
return rst;
}
deltaX 1和deltaY 3应该大于sqrt(10)
此代码是另一个试用版,但它也不符合数字现实 请帮忙!
#include <stdio.h>
#include <math.h>
#define LIM_N 3
#define LIM_M 3
#define LIM_E 0.0000001
main() {
int n = 0;
int m = 0;
int d = 0;
double dim = 0.0;
double x1 = 0.0;
double x2 = 0.0;
double pr = 0.0;
double res = 0.0;
if(LIM_M > LIM_N) {
for(d = 1; pow(10,d) <= LIM_M; d++) {
}
dim = pow(10,d - 1);
for(n = 2, m = 1; n <= (int) LIM_M + 1; n++, m++) {
x1 = sqrt((sqrt(2.0) / ((double) LIM_M / (double) LIM_N) * sqrt(2.0) / ((double) LIM_M) / (double) LIM_N) + ((double)LIM_E) / 2.0*((double)LIM_E) / 2.0) + (sqrt(2.0) / (double) 2.0);
res = dim * x1;
}
fprintf(stdout, "sqrt(1. %.64lf + %.64lf) = %.64f\n",x1, x2, res);
}
if(LIM_M < LIM_N) {
for(d = 1; pow(10,d) <= LIM_N; d++) {
}
dim = pow(10,d - 1);
for(n = 2, m = 1; n <= (int) LIM_N + 1; n++, m++) {
x1 = sqrt((sqrt(2.0) / ((double) LIM_N / (double) LIM_M) * sqrt(2.0) / ((double) LIM_N) * (double) LIM_M) + ((double)LIM_E) / 2.0*((double)LIM_E) / 2.0) + (sqrt(2.0) / (double) 2.0);
x2 = sqrt(sqrt(2.0/(double)LIM_N)*sqrt(2.0/(double)LIM_N))+(LIM_E/(double)LIM_N)*(LIM_E/(double)LIM_N) + (sqrt(2.0)/(double)LIM_M);
res = dim * x1;
}
fprintf(stdout, "sqrt(2. %.64lf + %.64lf) = %.64f\n",x1, x2, res);
}
if(LIM_M == LIM_N) {
for(d = 1; pow(10,d) <= LIM_M; d++) {
}
dim = pow(10,d - 1);
for(n = 2, m = 1; n <= (int) LIM_M + 1; n++, m++) {
x1 = 0.5*sqrt((sqrt(2.0) / ((double) 1.0) * sqrt(2.0) / ((double) 1.0)) + ((double)LIM_E) / 2.0*((double)LIM_E) / 2.0) + (sqrt(2.0) / (double) 2.0);
x2 = sqrt(sqrt(2.0/(double)LIM_N)*sqrt(2.0/(double)LIM_N))+(LIM_E/(double)LIM_N)*(LIM_E/(double)LIM_N) + (sqrt(2.0)/(double)LIM_M);
res = dim*x1;
}
fprintf(stdout, "sqrt(3. %.64lf + %.64lf) = %.64f\n",x1, x2, res);
}
}
好!我想我明白了!看看
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define MAX_STEP 100
#define dltX 1.0
#define dltY 2.0
struct vector {
double *x;
double *y;
double *len;
} vec;
struct index {
int n;
} idx;
struct result {
double tmpX;
double tmpY;
double sum;
} res;
double func_cLen(int n);
double func_p(int val);
main() {
vec.x = (double *) malloc(MAX_STEP*sizeof(double));
vec.y = (double *) malloc(MAX_STEP*sizeof(double));
vec.len = (double *) malloc(MAX_STEP*sizeof(double));
res.tmpX = dltX;
res.tmpY = dltY;
idx.n = 0;
for(idx.n = 1; idx.n <= MAX_STEP; idx.n++) {
vec.len[idx.n - 1] = func_cLen(idx.n);
res.sum = vec.len[idx.n - 1];
fprintf(stdout, "%8.16lf _ %8.16lf\n", vec.len[idx.n - 1], res.sum);
}
fprintf(stdout, "%8.16lf", res.sum);
free(vec.x);
free(vec.y);
free(vec.len);
}
double func_p(int val) {
int p = 0;
for(p = 1; val >= pow(10.0,(double)p); p++) {
val -= pow(10.0,(double) p);
}
return (p - 1);
}
double func_cLen(int n) {
double r = 0.0;
if(dltX == dltY) {
r = (sqrt(dltX*dltX + dltX*dltX) + sqrt(dltX*dltX + dltX*dltX)) / (2.0);
} else {
if(dltX > dltY) {
r = (sqrt(dltX*dltX + dltX*dltX) + sqrt(dltX*dltX + res.tmpY*res.tmpY)) / (2.0);
res.tmpY = r;
}
if(dltX < dltY) {
r = (sqrt(dltY*dltY + dltY*dltY) + sqrt(dltY*dltY + res.tmpX*res.tmpX)) / (2.0);
res.tmpX = r;
}
}
return r;
}
好!问题只是在r r pi / 180中,此r的比例为(a + b)/ 2,但我认为不是全部吗?