473,769 Members | 7,097 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Numerical Recipes Rational Approximation Algorithm

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

Jul 26 '06
11 3372
On 2006-07-26, lcw1964 <le***********@ alumni.uwo.cawr ote:
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 too have been working on least-squares code
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 did mine from scratch pre-allocating memory in blocks for each matrix in
the computation and making extensive use of pointer arithmetic

The client said it had to be fast, and it is.
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.
It sounds to me like you've messed up somewhere and left float where it
should now say double, or someone put '4' where they should have put
'sizeof(float)' and that's giving you problems.

It's also possible that you've got an error somewhere else that's corrupting
the heap.

Bye.
Jasen
Jul 29 '06 #11
I gave up on cygwin, but a barebones download and installation of MinGW
has been a good place to start.
You can find a small tutorial on how to install cygwin at

http://www.imtek.uni-freiburg.de/sim...lab/compiling/

and in the same directory a simple example on how to compile a simple
application with gcc.
Thanks for the tip. As a rank novice I have avoid command line
compilers like the place, but if this is free and it works, it is about
time I learned!
Command line is not too difficult. Its advantage over GUI is that the
expressive power of the scripting language is much higher than that of
GUI. You have to learn it, no doubt, but then many things can be done
much more easier.

It also makes sense to learn make and be able to read/write makefiles.
Again, it is not too difficult.

Best wishes,

Evgenii
--
http://Evgenii.Rudnyi.Ru/
http://ModelReduction.com/

Jul 29 '06 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
2421
by: Mike Meyer | last post by:
PEP: XXX Title: A rational number module for Python Version: $Revision: 1.4 $ Last-Modified: $Date: 2003/09/22 04:51:50 $ Author: Mike Meyer <mwm@mired.org> Status: Draft Type: Staqndards Content-Type: text/x-rst Created: 16-Dec-2004 Python-Version: 2.5
20
2147
by: Mike Meyer | last post by:
This version includes the input from various and sundry people. Thanks to everyone who contributed. <mike PEP: XXX Title: A rational number module for Python Version: $Revision: 1.4 $ Last-Modified: $Date: 2003/09/22 04:51:50 $ Author: Mike Meyer <mwm@mired.org>
2
2802
by: Brian van den Broek | last post by:
Hi all, I guess it is more of a maths question than a programming one, but it involves use of the decimal module, so here goes: As a self-directed learning exercise I've been working on a script to convert numbers to arbitrary bases. It aims to take any of whole numbers (python ints, longs, or Decimals), rational numbers (n / m n, m whole) and floating points (the best I can do for reals), and convert them to any base between 2 and...
5
3032
by: Edward Hua | last post by:
Hi, I'm wondering if anybody has ever copied the quicksort algorithm from the book Numerical Recipes in C: The Art of Scientific Computing (2nd ed.), by Press, Teukolsky, Vetterling, and Flannery, in Chapter 8. Quicsort is supposed to sort an array of, say, doubles, in ascending order. I tried to copy this algorithm line by line to test it. It seems that there's an error in this algorithm as given in this book. Namely, the
16
3279
by: Martin Jørgensen | last post by:
Hi, I've made a program from numerical recipes. Looks like I'm not allowed to distribute the source code from numerical recipes but it shouldn't even be necessary to do that. My problem is that I'm not very experienced with pointers, pointers to pointers and the like and I got 4 compiler warnings + I don't completely understand how to build this "compact matrix" (see later).
23
15689
by: Abhi | last post by:
Hi.. I wanted the C source code in machine readable format for the book "Numerical Recipes in C". I got hold of the pdf version of the book somehow. Does anyone have the complete C code of the book?. If yes,..can you please mail me the code or somehow share it with me?. With Regards, Abhishek S
10
3224
by: CBFalconer | last post by:
Here is an amusing toy, which may be of especial interest to the Forthians who use rational fractions to represent real numbers. The handling of criterion may also be interesting to some. /* Find best rational approximation to a double */ /* by C.B. Falconer, 2006-09-07. Released to public domain */ #include <stdio.h> #include <stdlib.h> #include <math.h>
10
5430
by: Babak | last post by:
Hi, I've developed a C program which contains a large number of vectors and matrices operations. Throughout my code, I used the template from the Numerical Recipes book to define vectors and matrices and access their elements. For example, to define a vector I used the function: my_vector=vector(0,n-1); Which actually allocate the memory as follows:
6
4249
by: Giovanni Gherdovich | last post by:
Hello, I need to perform a two-dimensional numerical integration, i.e. my functions are R^2 -R. All the tool I'm aware of provide routines for single-variable numerical integration, so I'm about to write a "wrapper" wich uses a 1-D method "two times", applying Fubini's Theorem
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10214
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10048
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9996
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9865
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5304
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3963
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.