avatar
let me ask a question again# Computation - 科学计算
K*N
1
who knows if C has "long double" type?
在numerical计算的时候通常会set up一个精度EPS,这个值和你定义的type有什么
关系。 比如,我的type都是double, 如果EPS=1.0e-10,会有什么问题么?
avatar
h*o
2
有.....ld = 3.1415926L;
double should be enough to handle EPS=1.e-10
you can also try this.
double a, b;
a = b = 3.0;
a += 1.e-10;
if (a == b)
printf("try long double");
else
printf("double is enough");

【在 K*****N 的大作中提到】
: who knows if C has "long double" type?
: 在numerical计算的时候通常会set up一个精度EPS,这个值和你定义的type有什么
: 关系。 比如,我的type都是double, 如果EPS=1.0e-10,会有什么问题么?

avatar
b*y
3
C has long double, but may not be implemented by particular compiler,
since there is little numerical advantage to do long double rather
than just double precision. In double precision, eps = 1e-16 which
is enough to handle your 1e-10. For single precision, eps = 1e-07.
Most numerical computation is carried under either single or double
precision, which are IEEE standard, using 32 or 64 bits coding and very
easy to handle with modern computer architecture. One can
achieve arbitrary eps such as 1

【在 K*****N 的大作中提到】
: who knows if C has "long double" type?
: 在numerical计算的时候通常会set up一个精度EPS,这个值和你定义的type有什么
: 关系。 比如,我的type都是double, 如果EPS=1.0e-10,会有什么问题么?

avatar
K*N
4
thanks. yes. from numerical recipe, i read some info. about double and
float. for double, it's up to 10e-15 and for float, it's up to 3.0e-8.
it makes sense to me.
however, if you would, please take a look at
page 717 in http://www.library.cornell.edu/nr/bookcpdf/c16-2.pdf.
i am still confused about what epsion value it could be. In the book, it says
"the number like 10e-6 or whatever...." i am very confused about what does
"whatever" mean.
best wishes,
Wilson

【在 b*****y 的大作中提到】
: C has long double, but may not be implemented by particular compiler,
: since there is little numerical advantage to do long double rather
: than just double precision. In double precision, eps = 1e-16 which
: is enough to handle your 1e-10. For single precision, eps = 1e-07.
: Most numerical computation is carried under either single or double
: precision, which are IEEE standard, using 32 or 64 bits coding and very
: easy to handle with modern computer architecture. One can
: achieve arbitrary eps such as 1

avatar
h*o
5
1.e-6 is from the example mentioned above, "get a solution good to
one part of in 1e+6" (1 ppm)
The basic idea in that part is to initiate the discussion of
choosing good scale values.
You are solving ODE with initial values?

【在 K*****N 的大作中提到】
: thanks. yes. from numerical recipe, i read some info. about double and
: float. for double, it's up to 10e-15 and for float, it's up to 3.0e-8.
: it makes sense to me.
: however, if you would, please take a look at
: page 717 in http://www.library.cornell.edu/nr/bookcpdf/c16-2.pdf.
: i am still confused about what epsion value it could be. In the book, it says
: "the number like 10e-6 or whatever...." i am very confused about what does
: "whatever" mean.
: best wishes,
: Wilson

avatar
h*o
6
btw...you can also test if 'double' is enough for your ESP
as long as you know the scale values for your problem.
basically, a good numerical routine/function should be able to
notice the underflow problem. for example page 714 of NR in C
"if ((float)(x+h) == x) nrerror("step size too small in routine rkdmb");"

【在 h***o 的大作中提到】
: 1.e-6 is from the example mentioned above, "get a solution good to
: one part of in 1e+6" (1 ppm)
: The basic idea in that part is to initiate the discussion of
: choosing good scale values.
: You are solving ODE with initial values?

avatar
b*y
7

They talked about solving a system of ODEs which consists of state variables
with different magnitudes. If you want to solve the system with one tolerance,
you have to make sure every equation achieve that accuracy. 10e-06 means
the tolerance (eps here). The scaling part comes in because some state
variables may not need such a high accuracy as 1e-06, so you use scaling
vector to make the magnitudes of state variables close to each other.
To clarify the terminology, in double precision under IE

【在 K*****N 的大作中提到】
: thanks. yes. from numerical recipe, i read some info. about double and
: float. for double, it's up to 10e-15 and for float, it's up to 3.0e-8.
: it makes sense to me.
: however, if you would, please take a look at
: page 717 in http://www.library.cornell.edu/nr/bookcpdf/c16-2.pdf.
: i am still confused about what epsion value it could be. In the book, it says
: "the number like 10e-6 or whatever...." i am very confused about what does
: "whatever" mean.
: best wishes,
: Wilson

avatar
K*N
8
thanks all. I got it. by testing, it seems that eps (or more precisely,
i should say tolerance?!) i could set up in the program is about 1.0e-33
for double, but for float it's about 1.0e-15. any higher precision above
these two number will have error message (underflow).
thanks again.
wishes

【在 b*****y 的大作中提到】
:
: They talked about solving a system of ODEs which consists of state variables
: with different magnitudes. If you want to solve the system with one tolerance,
: you have to make sure every equation achieve that accuracy. 10e-06 means
: the tolerance (eps here). The scaling part comes in because some state
: variables may not need such a high accuracy as 1e-06, so you use scaling
: vector to make the magnitudes of state variables close to each other.
: To clarify the terminology, in double precision under IE

avatar
K*N
9
you suggest me to test:
if (fabs(y[i])+fabs(yscal[i]*eps)) > fabs(y[i])
printf("double is enough\n");
in that case, eps for double could be much smaller. but that's probably
not the right way to test, since the algorithm is not as what you and I had
thought. bascially, it compare:
if ( delta1 < yscal[i]*eps )
next step;
else
decrease the stepsize;
where delta1 is the estimated error.
so in such case, eps could be much smaller.
but your other suggestion is very helpful for me. thank u v

【在 h***o 的大作中提到】
: btw...you can also test if 'double' is enough for your ESP
: as long as you know the scale values for your problem.
: basically, a good numerical routine/function should be able to
: notice the underflow problem. for example page 714 of NR in C
: "if ((float)(x+h) == x) nrerror("step size too small in routine rkdmb");"

avatar
h*o
10
hehe...in this case it really depends on which variable is
the smallest, yscale or stepsize.

【在 K*****N 的大作中提到】
: you suggest me to test:
: if (fabs(y[i])+fabs(yscal[i]*eps)) > fabs(y[i])
: printf("double is enough\n");
: in that case, eps for double could be much smaller. but that's probably
: not the right way to test, since the algorithm is not as what you and I had
: thought. bascially, it compare:
: if ( delta1 < yscal[i]*eps )
: next step;
: else
: decrease the stepsize;

avatar
K*N
11
hehe. now i understand better. eps value somehow is different machine
accuarcy. eps value could be very small for double, like eps=1.0e-30 is
okay by using "double".
however, on the other hand, if u have some expression, like 1.0+eps, then
it might be hurt by declair "double". therefore, instead, you still need
use "long double"..

【在 h***o 的大作中提到】
: hehe...in this case it really depends on which variable is
: the smallest, yscale or stepsize.

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。