Hello all,
I am a beginner programmer so please bear with me if I appear to be missing something obvious. I am using Fortran 95 and compiling with Nag 5.2.
I am attempting to evaluate the value of a polynomial at different values of x. The polynomial contains 'j' terms.
I have created 2 allocatable arrays, the first containing values of x and the second containing the exponents of a polynomial of x. i.e. [x1 x2 x3 ... xn] and [exponent1, exponent2, exponent3 ... exponentj]
The program then evaluates
x1^exponent1 + x1^exponent2 ... x1^exponentj
x2^exponent1 + x2^exponent2 ... x2^exponentj
.
.
.
xn^exponent1 + xn^exponent2 ... xn^exponentj
and puts the results in n number of arrays of size j
My problem is that because both of the arrays are double precision, if one of the x values is 0 then I get a floating point error. How do I overcome this? I cannot know in advance what the user input x values are, and x=0 will very probably be an input.
Thanks in advance. Apologies if my question strikes you as extremely basic. (I am an engineer not a programmer).
I am a beginner programmer so please bear with me if I appear to be missing something obvious. I am using Fortran 95 and compiling with Nag 5.2.
I am attempting to evaluate the value of a polynomial at different values of x. The polynomial contains 'j' terms.
I have created 2 allocatable arrays, the first containing values of x and the second containing the exponents of a polynomial of x. i.e. [x1 x2 x3 ... xn] and [exponent1, exponent2, exponent3 ... exponentj]
The program then evaluates
x1^exponent1 + x1^exponent2 ... x1^exponentj
x2^exponent1 + x2^exponent2 ... x2^exponentj
.
.
.
xn^exponent1 + xn^exponent2 ... xn^exponentj
and puts the results in n number of arrays of size j
My problem is that because both of the arrays are double precision, if one of the x values is 0 then I get a floating point error. How do I overcome this? I cannot know in advance what the user input x values are, and x=0 will very probably be an input.
Thanks in advance. Apologies if my question strikes you as extremely basic. (I am an engineer not a programmer).