User Profile

Collapse

Profile Sidebar

Collapse
emaghero
emaghero
Last Activity: Aug 7 '13, 03:10 PM
Joined: Oct 19 '06
Location: Cork City, Republic of Ireland
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • emaghero
    replied to Repeated dynamic memory allocation
    in C
    The matrices A, B are dynamically allocated by creating an array of arrays.

    Code:
    int size = some_number; 
    A = new double *[size+1];
    for(int i=1;i<=size; i++){
    A[i] = new double [size+1]; 
    }
    The define functions are only there to illustrate what the algorithm is doing. I didn't want to clutter the post with unnecessary detail.

    It seems that the answer to my question depends...
    See more | Go to post

    Leave a comment:


  • emaghero
    started a topic Repeated dynamic memory allocation
    in C

    Repeated dynamic memory allocation

    I'm simulating the propagation of waves in 3D, to step a distance dz requires the solution of a system of linear equations of the form A.x^{new} = B.x^{old}, where x represents the shape of the wave, and A, B are large-ish N*N arrays of type double. The process is represented by

    Code:
    int Nsteps, Npos;
    
    double dz;
    
    // arrays to hold the field values
    double *x_old;
    double *x_new;
    ...
    See more | Go to post

  • How do I use a generic array class inside another class?

    I am trying to use the attached header file, which provides me with a generic way of declarating arrays and matrices of arbitrary size.

    I would like to be able to use the classes Array and Matrix inside another class to perform calculations with arrays and matrices of type double and complex<double> . This second class, called LinAlgCalc, contains algorithms for solving A.x=b etc. I have attempted to define the class as follows...
    See more | Go to post

  • Get a good numerical analysis text from a library, "Numerical Analysis" by Burden and Faires gives an explanation of how to fit a curve to a data set using cubic splines. If you just want the code then you can probably find it in "Numerical Recipes in C" by Press et al.
    See more | Go to post

    Leave a comment:


  • The text "Numerical Recipes in C" contains a chapter on random number generation. The chapter describes the techniques used to create random numbers from distributions. It also includes C source code.
    See more | Go to post

    Leave a comment:


  • Thanks for the replies.
    See more | Go to post

    Leave a comment:


  • Scope of Dynamically Allocated Arrays in class member functions

    I have the following class declaration
    Code:
    class class_name{
    public:
       class_name(); // Constructor
    
    // Member functions
       void function_1();
       void function_2(double *mat);
       void function_3();
    
       void function_2_re_def(double *mat);
       void function_3_re_def();
    
    public:
       int rows;
       int cols;
    
       double *v1;
    ...
    See more | Go to post

  • Reading data from a file into a dynamically allocated array

    Afternoon all,

    I am trying to read data from a file into an array. The array size is uknown before I open the file and count the number of data points. The function I have in mind is the following

    Code:
    void read_data(char *file,int &ndata,double *x,double *y)
    {
    	//Read the data from the file and store it in memory
    	//This reads the data stored in the two column file and stores it in memory
    ...
    See more | Go to post

  • Just found a really easy way to get this done
    Code:
    char *overlapfile;
    
    overlapfile=(char *)(f1.c_str());
    Thanks for all the help....
    See more | Go to post

    Leave a comment:


  • On a related note,

    Suppose I want to open a binary file for import / export using

    Code:
    int file;
    errno_t err=_sopen_s(&file,overlapfile,_O_BINARY,_SH_DENYNO,_S_IREAD);
    
    if(file==-1){
        perror("Failed to open file");
    }
    else{
        //Import data
    }
    The parameter overlapfile is of type
    Code:
    const char *
    Is there...
    See more | Go to post

    Leave a comment:


  • Cheers, thanks very much....
    See more | Go to post

    Leave a comment:


  • emaghero
    started a topic sprintf equivalent for the string class <string>
    in C

    sprintf equivalent for the string class <string>

    Morning all,

    I am currently processing some data that is contained in several files in several different locations. The filenames contain descriptions of the data that I am working with, for example rect_W_7.2_H_3. 8.txt

    I am using the STL string class on MSVS to name the directories storing the files.
    Code:
    string drive="c:\\"
    string dir1="Output_Files\\";
    string dir2="Calculation_Data\\";
    ...
    See more | Go to post

  • emaghero
    replied to Reading Data from a CSV file
    in C
    I only need to be able to read in different sets of experimental data that I already have. So I won't be using it as part of something else that will have to accomodate multiple file formats....
    See more | Go to post

    Leave a comment:


  • emaghero
    replied to Reading Data from a CSV file
    in C
    Thanks very much.

    That did the trick.

    I replaced the line

    Code:
    pos=(int)(strcspn(buf,","));
    with

    Code:
    posa=(int)(strcspn(buf,","));
    posb=(int)(strcspn(buf,"\n"));
    pos=Min(posa,posb); // Min is a template function that returns the minimum of posa and posb
    and that took care of it....
    See more | Go to post

    Leave a comment:


  • emaghero
    started a topic Reading Data from a CSV file
    in C

    Reading Data from a CSV file

    Greetings all,

    I have a small amount of data that I want to read from a CSV file.

    The data is stored in an array of size rows*cols, the array is zero-based.

    I open the file using an fstream object

    Code:
    ifstream data;
    data.open(file,ios_base::in);
    I create a buffer to store the data

    Code:
    int buf_size=1024*1024*10;
    char *BUF=new(char[buf_size]);
    ...
    See more | Go to post

  • emaghero
    replied to Pointers to Class Members
    in C
    So, is it the case that I can't do what I was trying to do unless I use functors?

    I guess I better get reading then.

    Thanks very much for your help....
    See more | Go to post

    Leave a comment:


  • emaghero
    started a topic Pointers to Class Members
    in C

    Pointers to Class Members

    I have the following class defined in code

    Code:
    //header file
    
    class froot{
    public:
    	void calculate_root(int i);
    	double F(double x);
    	double G(double x);
    	
    	double find_root(double (*g)(double),double x1,double x2,int &depth);
    	double root(double x1,double x2,double (*g)(double),double f1,double f2,int &depth);
    
    private:
    ...
    See more | Go to post

  • emaghero
    replied to Preprocessor Question
    in C
    Thanks very much for all your help.
    See more | Go to post

    Leave a comment:


  • emaghero
    started a topic Preprocessor Question
    in C

    Preprocessor Question

    Greetings one and all,

    I have a query about the preprocessor directive.

    I am coding in C++ in the MS Visual Studio environment.

    I was updating an old code recently where I had defined PI using the #define directive.

    Code:
    #define PI 3.1415926535897932385
    I decided to change this to

    Code:
    #define PI 4.0*atan(1.0)
    And the code ceased to work correctly. I think what...
    See more | Go to post

  • emaghero
    replied to Ackermann's function
    in C
    Google it. Enter Ackermann Function into Google and the first site you get gives plenty of info....
    See more | Go to post

    Leave a comment:

No activity results to display
Show More
Working...