数值配方有理逼近算法 [英] Numerical Recipes Rational Approximation Algorithm

查看:74
本文介绍了数值配方有理逼近算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问候小组!我是C编程和

数值分析的新手,所以我提前请你放纵。此外,这个

问题专门针对那些熟悉C语言(非C ++)的数据,在实践中或至少在理论上。


我对NR,第2版第5.13节中提供的Remes算法的最小二乘SVD替代品感兴趣。 (见这里,
http:// www.library.cornell.edu/nr/bookcpdf/c5-13.pdf ,供参考)。


我拥有NR代码文件(所以,是的,我我是合法的!)并且付出了一丝不苟的关注各种文件依赖关系我已经能够设置

并在Borland C ++ 3.1中编译一个项目(是的,旧的编译器) ,但

代码差不多,这应该是演示ratlsqr

例程。那些拥有相同文件集的人将会知道xratlsqr.c

文件,这不在书中。由于ratslqr例程使用了两个关键的SVD程序的浮动版本,我不得不进入并且

严格改变标题和相关的变量声明来自

浮动加倍。


编译得很好,但我运行的时候我给示例程序提供了一些

值的小尺寸测试问题,我直接从nrutil文件中得到一个运行时错误

:矩阵()中的分配错误或者,

次vector()中的分配错误或类似的东西。


我知道例程在指定适当的例程时遇到问题

例程所需的各种向量和矩阵的内存空间,

但是在一台新的快速英特尔型机器上应该有堆内存给

备用。


我编译并运行其他示例程序,根据NR包装器分配内存用于
向量和矩阵。在

nrutil文件中提供,它们工作正常。请注意,它们有点不那么复杂(SVD例程是NR中最长和最复杂的

),并且没有任何事后摆弄浮动双倍

问题。我只是想知道我是否在试图为b / b
为双倍大小的浮点阵列分配空间时吞噬内存,但在示例中我想要测试这个不应该是对于任何现代的b $ b计算机都太费力了。


这与我编译的内存模型有关吗?我尝试了从小到大的选项,但无济于事!


这是一个非常专业的问题,我知道,也许我有除了那些直接熟悉

困扰我的例程之外,任何人都没有意义。但是如果你熟悉NR的动态内存分配问题,或者更好的是,特别感兴趣的代码是

,也许你可以帮我神秘化。


非常感谢提前,


Les

Greetings groups! I am a rank novice in both C programming and
numerical analysis, so I ask in advance your indulgence. Also, this
question is directed specifically to those familiar with Numerical
Recipes in C (not C++), in practice or at least in theory.

I have taken an interest in the the least-squares SVD alternative to
the Remes algorithm offered in section 5.13 of NR, 2nd ed. (see here,
http://www.library.cornell.edu/nr/bookcpdf/c5-13.pdf, for reference).

I own the NR code files (so, yes, I am legal!) and in paying scrupulous
attention to the various file dependencies I have been able to set up
and compile a project in Borland C++ 3.1 (yes, old compiler, but the
code is about as old) that is supposed to demonstrate the ratlsqr
routine. Those who own the same file set will know about the xratlsqr.c
file, which is not in the book. Since the ratslqr routine uses a double
vs float version of the key SVD procedures, I have had to go in and
scrupulously change the headers and relevant varible declarations from
float to double.

Things compile fine, but I run time I feed the example program some
values for a small size test problem, and I get a runtime error
straight out of the nrutil file: "allocation error in matrix()" or, at
times "allocation error in vector()", or something similar.

I know that the routine is having trouble designating the appropriate
memory space for the various vectors and matrices the routine requires,
but on a new fast Intel type machine there should be heap memory to
spare.

I have compiled and run other sample programs that allocate memory for
vectors and matrices according to the NR "wrappers" provided in the
nrutil files, and they work fine. Mind you , they are a little less
complicated (the SVD routines are among the lengthiest and most complex
in NR), and there was no post hoc fiddling around the float to double
issue. I am just wondering if I am gobbling up memory in trying to
allocate space for arrays of double size floats, but in the examples I
am trying to test this should not be too taxing for any modern
computer.

Is this related to the memory model under which I compile? I have tried
the options ranging from tiny to huge, but to no avail!

This is a highly specialized question, I know, and probably I have made
little sense to any but those directly familiar with the routines that
perplex me. But if you are familiar with dynamic memory allocation
issues with NR or, better yet, specifically interested in the very code
in question, maybe you can help demystify me.

Many thanks in advance,

Les

推荐答案

lcw1964写道:
lcw1964 wrote:

问候小组!我是C编程和

数值分析的新手,所以我提前请你放纵。此外,这个

问题专门针对那些熟悉C语言(非C ++)的数据,在实践中或至少在理论上。


我对NR,第2版第5.13节中提供的Remes算法的最小二乘SVD替代品感兴趣。 (见这里,
http:// www.library.cornell.edu/nr/bookcpdf/c5-13.pdf ,供参考)。


我拥有NR代码文件(所以,是的,我我是合法的!)并且付出了一丝不苟的关注各种文件依赖关系我已经能够设置

并在Borland C ++ 3.1中编译一个项目(是的,旧的编译器) ,但

代码差不多,这应该是演示ratlsqr

例程。那些拥有相同文件集的人将会知道xratlsqr.c

文件,这不在书中。由于ratslqr例程使用了两个关键的SVD程序的浮动版本,我不得不进入并且

严格改变标题和相关的变量声明来自

浮动加倍。


编译得很好,但我运行的时候我给示例程序提供了一些

值的小尺寸测试问题,我直接从nrutil文件中得到一个运行时错误

:矩阵()中的分配错误或者,

次vector()中的分配错误或类似的东西。


我知道例程在指定适当的例程时遇到问题

例程所需的各种向量和矩阵的内存空间,

但是在一台新的快速英特尔型机器上应该有堆内存给

备用。


我编译并运行其他示例程序,根据NR包装器分配内存用于
向量和矩阵。在

nrutil文件中提供,它们工作正常。请注意,它们有点不那么复杂(SVD例程是NR中最长和最复杂的

),并且没有任何事后摆弄浮动双倍

问题。我只是想知道我是否在试图为b / b
为双倍大小的浮点阵列分配空间时吞噬内存,但在示例中我想要测试这个不应该是对于任何现代的b $ b计算机都太费力了。


这与我编译的内存模型有关吗?我尝试了从小到大的选项,但无济于事!


这是一个非常专业的问题,我知道,也许我有除了那些直接熟悉

困扰我的例程之外,任何人都没有意义。但是如果你熟悉NR的动态内存分配问题,或者更好的是,特别感兴趣的代码是

,也许你可以帮我神秘化。


非常感谢提前,


Les
Greetings groups! I am a rank novice in both C programming and
numerical analysis, so I ask in advance your indulgence. Also, this
question is directed specifically to those familiar with Numerical
Recipes in C (not C++), in practice or at least in theory.

I have taken an interest in the the least-squares SVD alternative to
the Remes algorithm offered in section 5.13 of NR, 2nd ed. (see here,
http://www.library.cornell.edu/nr/bookcpdf/c5-13.pdf, for reference).

I own the NR code files (so, yes, I am legal!) and in paying scrupulous
attention to the various file dependencies I have been able to set up
and compile a project in Borland C++ 3.1 (yes, old compiler, but the
code is about as old) that is supposed to demonstrate the ratlsqr
routine. Those who own the same file set will know about the xratlsqr.c
file, which is not in the book. Since the ratslqr routine uses a double
vs float version of the key SVD procedures, I have had to go in and
scrupulously change the headers and relevant varible declarations from
float to double.

Things compile fine, but I run time I feed the example program some
values for a small size test problem, and I get a runtime error
straight out of the nrutil file: "allocation error in matrix()" or, at
times "allocation error in vector()", or something similar.

I know that the routine is having trouble designating the appropriate
memory space for the various vectors and matrices the routine requires,
but on a new fast Intel type machine there should be heap memory to
spare.

I have compiled and run other sample programs that allocate memory for
vectors and matrices according to the NR "wrappers" provided in the
nrutil files, and they work fine. Mind you , they are a little less
complicated (the SVD routines are among the lengthiest and most complex
in NR), and there was no post hoc fiddling around the float to double
issue. I am just wondering if I am gobbling up memory in trying to
allocate space for arrays of double size floats, but in the examples I
am trying to test this should not be too taxing for any modern
computer.

Is this related to the memory model under which I compile? I have tried
the options ranging from tiny to huge, but to no avail!

This is a highly specialized question, I know, and probably I have made
little sense to any but those directly familiar with the routines that
perplex me. But if you are familiar with dynamic memory allocation
issues with NR or, better yet, specifically interested in the very code
in question, maybe you can help demystify me.

Many thanks in advance,

Les



我有类似的问题& ;转换" NR C代码加倍精度。

现在我使用NR(不常见,发现他们的代码难以遵循)

它是C ++代码,它在默认情况下是双精度。


我的问题可以追溯到各种TINY和EPS变量

,其值在其来源的某处被硬编码,但通过什么

你告诉我不太确定'这是你的理由。也许你可以在mingw下安装一个更新的编译器,如gcc(我假设你使用的是
。)然后你可以尝试运行你的

valgrind(valgrind.org)下的可执行文件,看看你的资源来源在哪里分配

错了。这可能会给你一个线索。


希望有所帮助,

S.

I had similar problems "converting" NR C code to double precision.
Nowadays when I use NR (not very often, find their code hard to follow)
it''s the C++ code which is in double precision by default.

My problem could be traced back to all kinds of TINY and EPS variables
whose values had been hard-coded somewhere in their source, but by what
you tell I''m not so sure that''s the reason in your case. Perhaps you
could install a more up-to-date compiler like gcc under mingw (I assume
you''re using Windows.) Then you could try to run your executable under
valgrind (valgrind.org) to see where in your source the allocation goes
wrong. That may give you a clue.

Hope that helps,
S.


lcw1964写道:
lcw1964 wrote:

问候小组!我是C编程和

数值分析的新手,所以我提前请你放纵。此外,这个

问题专门针对那些熟悉C语言(非C ++)的数据,在实践中或至少在理论上。


我对NR,第2版第5.13节中提供的Remes算法的最小二乘SVD替代品感兴趣。 (见这里,
http:// www.library.cornell.edu/nr/bookcpdf/c5-13.pdf ,供参考)。


我拥有NR代码文件(所以,是的,我我是合法的!)并且付出了一丝不苟的关注各种文件依赖关系我已经能够设置

并在Borland C ++ 3.1中编译一个项目(是的,旧的编译器) ,但

代码差不多,这应该是演示ratlsqr

例程。那些拥有相同文件集的人将会知道xratlsqr.c

文件,这不在书中。由于ratslqr例程使用了两个关键的SVD程序的浮动版本,我不得不进入并且

严格改变标题和相关的变量声明来自

浮动加倍。


编译得很好,但我运行的时候我给示例程序提供了一些

值的小尺寸测试问题,我直接从nrutil文件中得到一个运行时错误

:矩阵()中的分配错误或者,

次vector()中的分配错误或类似的东西。


我知道例程在指定适当的例程时遇到问题

例程所需的各种向量和矩阵的内存空间,

但是在一台新的快速英特尔型机器上应该有堆内存给

备用。


我编译并运行其他示例程序,根据NR包装器分配内存用于
向量和矩阵。在

nrutil文件中提供,它们工作正常。请注意,它们有点不那么复杂(SVD例程是NR中最长和最复杂的

),并且没有任何事后摆弄浮动双倍

问题。我只是想知道我是否在试图为b / b
为双倍大小的浮点阵列分配空间时吞噬内存,但在示例中我想要测试这个不应该是对于任何现代的b $ b计算机都太费力了。


这与我编译的内存模型有关吗?我尝试了从小到大的选项,但无济于事!


这是一个非常专业的问题,我知道,也许我有除了那些直接熟悉

困扰我的例程之外,任何人都没有意义。但是如果你熟悉NR的动态内存分配问题,或者更好的是,特别感兴趣的代码是

,也许你可以帮我神秘化。


非常感谢提前,


Les
Greetings groups! I am a rank novice in both C programming and
numerical analysis, so I ask in advance your indulgence. Also, this
question is directed specifically to those familiar with Numerical
Recipes in C (not C++), in practice or at least in theory.

I have taken an interest in the the least-squares SVD alternative to
the Remes algorithm offered in section 5.13 of NR, 2nd ed. (see here,
http://www.library.cornell.edu/nr/bookcpdf/c5-13.pdf, for reference).

I own the NR code files (so, yes, I am legal!) and in paying scrupulous
attention to the various file dependencies I have been able to set up
and compile a project in Borland C++ 3.1 (yes, old compiler, but the
code is about as old) that is supposed to demonstrate the ratlsqr
routine. Those who own the same file set will know about the xratlsqr.c
file, which is not in the book. Since the ratslqr routine uses a double
vs float version of the key SVD procedures, I have had to go in and
scrupulously change the headers and relevant varible declarations from
float to double.

Things compile fine, but I run time I feed the example program some
values for a small size test problem, and I get a runtime error
straight out of the nrutil file: "allocation error in matrix()" or, at
times "allocation error in vector()", or something similar.

I know that the routine is having trouble designating the appropriate
memory space for the various vectors and matrices the routine requires,
but on a new fast Intel type machine there should be heap memory to
spare.

I have compiled and run other sample programs that allocate memory for
vectors and matrices according to the NR "wrappers" provided in the
nrutil files, and they work fine. Mind you , they are a little less
complicated (the SVD routines are among the lengthiest and most complex
in NR), and there was no post hoc fiddling around the float to double
issue. I am just wondering if I am gobbling up memory in trying to
allocate space for arrays of double size floats, but in the examples I
am trying to test this should not be too taxing for any modern
computer.

Is this related to the memory model under which I compile? I have tried
the options ranging from tiny to huge, but to no avail!

This is a highly specialized question, I know, and probably I have made
little sense to any but those directly familiar with the routines that
perplex me. But if you are familiar with dynamic memory allocation
issues with NR or, better yet, specifically interested in the very code
in question, maybe you can help demystify me.

Many thanks in advance,

Les



忘记提及你了也可以尝试在nr.com论坛上发帖。

可能你不是唯一的受害者。

Forgot to mention that you might also try posting on the nr.com forum.
Likely you''re not the only victim.




netlib / cephes / remes怎么样?

Hans M

-------------------- -------------------------------------------------- ----------------------------------------------

lcw1964写道:
Hi,
what about netlib/cephes/remes?
Hans M
--------------------------------------------------------------------------------------------------------------------
lcw1964 wrote:

问候小组!我是C编程和

数值分析的新手,所以我提前请你放纵。此外,这个

问题专门针对那些熟悉C语言(非C ++)的数据,在实践中或至少在理论上。


我对NR,第2版第5.13节中提供的Remes算法的最小二乘SVD替代品感兴趣。 (见这里,
http:// www.library.cornell.edu/nr/bookcpdf/c5-13.pdf ,供参考)。


我拥有NR代码文件(所以,是的,我我是合法的!)并且付出了一丝不苟的关注各种文件依赖关系我已经能够设置

并在Borland C ++ 3.1中编译一个项目(是的,旧的编译器) ,但

代码差不多,这应该是演示ratlsqr

例程。那些拥有相同文件集的人将会知道xratlsqr.c

文件,这不在书中。由于ratslqr例程使用了两个关键的SVD程序的浮动版本,我不得不进入并且

严格改变标题和相关的变量声明来自

浮动加倍。


编译得很好,但我运行的时候我给示例程序提供了一些

值的小尺寸测试问题,我直接从nrutil文件中得到一个运行时错误

:矩阵()中的分配错误或者,

次vector()中的分配错误或类似的东西。


我知道例程在指定适当的例程时遇到问题

例程所需的各种向量和矩阵的内存空间,

但是在一台新的快速英特尔型机器上应该有堆内存给

备用。


我编译并运行其他示例程序,根据NR包装器分配内存用于
向量和矩阵。在

nrutil文件中提供,它们工作正常。请注意,它们有点不那么复杂(SVD例程是NR中最长和最复杂的

),并且没有任何事后摆弄浮动双倍

问题。我只是想知道我是否在试图为b / b
为双倍大小的浮点阵列分配空间时吞噬内存,但在示例中我想要测试这个不应该是对于任何现代的b $ b计算机都太费力了。


这与我编译的内存模型有关吗?我尝试了从小到大的选项,但无济于事!


这是一个非常专业的问题,我知道,也许我有除了那些直接熟悉

困扰我的例程之外,任何人都没有意义。但是如果你熟悉NR的动态内存分配问题,或者更好的是,特别感兴趣的代码是

,也许你可以帮我神秘化。


非常感谢提前,


Les
Greetings groups! I am a rank novice in both C programming and
numerical analysis, so I ask in advance your indulgence. Also, this
question is directed specifically to those familiar with Numerical
Recipes in C (not C++), in practice or at least in theory.

I have taken an interest in the the least-squares SVD alternative to
the Remes algorithm offered in section 5.13 of NR, 2nd ed. (see here,
http://www.library.cornell.edu/nr/bookcpdf/c5-13.pdf, for reference).

I own the NR code files (so, yes, I am legal!) and in paying scrupulous
attention to the various file dependencies I have been able to set up
and compile a project in Borland C++ 3.1 (yes, old compiler, but the
code is about as old) that is supposed to demonstrate the ratlsqr
routine. Those who own the same file set will know about the xratlsqr.c
file, which is not in the book. Since the ratslqr routine uses a double
vs float version of the key SVD procedures, I have had to go in and
scrupulously change the headers and relevant varible declarations from
float to double.

Things compile fine, but I run time I feed the example program some
values for a small size test problem, and I get a runtime error
straight out of the nrutil file: "allocation error in matrix()" or, at
times "allocation error in vector()", or something similar.

I know that the routine is having trouble designating the appropriate
memory space for the various vectors and matrices the routine requires,
but on a new fast Intel type machine there should be heap memory to
spare.

I have compiled and run other sample programs that allocate memory for
vectors and matrices according to the NR "wrappers" provided in the
nrutil files, and they work fine. Mind you , they are a little less
complicated (the SVD routines are among the lengthiest and most complex
in NR), and there was no post hoc fiddling around the float to double
issue. I am just wondering if I am gobbling up memory in trying to
allocate space for arrays of double size floats, but in the examples I
am trying to test this should not be too taxing for any modern
computer.

Is this related to the memory model under which I compile? I have tried
the options ranging from tiny to huge, but to no avail!

This is a highly specialized question, I know, and probably I have made
little sense to any but those directly familiar with the routines that
perplex me. But if you are familiar with dynamic memory allocation
issues with NR or, better yet, specifically interested in the very code
in question, maybe you can help demystify me.

Many thanks in advance,

Les


这篇关于数值配方有理逼近算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆