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