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.
in the main function I have declared:
void newtonRaphson(double eps,int *pn2,double *a)
// 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;
// newtonRaphson main loop
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
b[k] = a[k];
// free the number_array's memory
// 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
}while (abs(a[k+1] - a[k])>eps);
// only one array element as a test, bcs nothing is working yet ..
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! =)