PDA

View Full Version : Plotting graph of 1/x



Persoontje
19th February 2009, 14:16
Hi,
I'm writing a little application to plot graphs using qt 4.4 and qwt.
The script is parsed using QtScript, and the program calculates for each x value an y value using the script. (with dx between the points). The points are then plotted using qwt.
This works good, but when you try to plot the graph for 1/x (or other functiosn returning NaN), there is a problem. Qwt draws the NaN value and you get the following graph instead of two "asymptotes":

Is there a way to solve this? (I could create two curves, one for -10 < x 0 and one for 0 < x < 10, but I would get problems with functions like 1 / (x -2)

Edit: I just did some others test and you get similiar problems with other graps with NaN values: for instance

Math.sqrt(plotx); (x ^ 0.5 )
and
Math.log(plotx); (ln(x))

john_god
20th March 2009, 14:26
You will also have trouble with graphs like this f(x)=1/((x-4)*(x+6)), you will have 2 NAN's.
You can solve this by defining a function (with the bissection algorithm, for example, or other ) to fing the zeros in the equation. You should then keep your zeros (this case, 4 and -6) in a list, and define as much graphs and limits as the zeros you get.
Remember that the zeros from a function = 1/f(x) are the NAN's from the f(x).