Thread: Newton-Raphson Iteration - logical problem

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    9

    Newton-Raphson Iteration - logical problem

    Hi.
    I'm working on a program that implements several numerical methods.
    This is the function for the Newton-Raphson method. I'd like to give the funcion the precison, number of steps, and an array in which every step is hold.

    Code:
    void newtonRaphson(double eps,int *pn2,double *a)
    {	
    	//variable declaration
    	// array: every calculated value is stored into it
    	double *b = 0;
    	int array_size = 10;
    	a = (double*) malloc(array_size*sizeof(double));
    	int k = 0;
    	a[k]=0;
    	// newtonRaphson main loop
    	do
    	{	
    		if (k == array_size)
    		{
    			b = (double*) malloc(array_size*2*sizeof(double)); // allocates space
    		
    			// the values of array have to be copied into the new_array
    			for(k=0;k<array_size;k++)
    				b[k] = a[k];
    		
    			// free the number_array's memory
    			free(a);
    		
    			// pointer pnumber_array shows in direction of pnew_number_array
    			a = b;
    		
    			// array_size = array_size * 2;
    			array_size *= 2; 
    		}
    		
    		double c = a[k];
    		a[k+1] = a[k] -(myfun(c)/myfun_der(c));
    		// k+1 slots occupied
    		k++; 
    	
    	}while (abs(a[k+1] - a[k])>eps);
                  // only one array element as a test, bcs nothing is working yet .. 
    	printf("%lf",a[k]);
    }
    in the main function I have declared:
    double array;
    int n1; EDIT: i dont manipulate it in the function yet, bcs nothing is working yet ..
    and eps is given by the user, but this shouln't be the fault bcs it is working in other functions .. neither the myfun,myfun_der functions which are also working ..

    thx for helping me! =)

    Greets
    matts
    Last edited by Matts; 05-25-2011 at 02:37 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newton raphson method - C
    By arazki1yes in forum C Programming
    Replies: 8
    Last Post: 04-04-2011, 01:11 PM
  2. Newton raphson
    By kariisa in forum C++ Programming
    Replies: 2
    Last Post: 03-24-2011, 08:13 AM
  3. using newton raphson method
    By sanskaar in forum C Programming
    Replies: 21
    Last Post: 09-27-2010, 12:02 AM
  4. Newton Raphson Method
    By zeb1d1ah in forum C Programming
    Replies: 2
    Last Post: 12-07-2009, 06:26 AM
  5. Newton Raphson method code
    By taebin in forum C++ Programming
    Replies: 2
    Last Post: 10-16-2004, 03:07 PM