# Thread: Plotting graph of 1/x

1. Novice
Join Date
Dec 2007
Posts
19
Thanks
2
Qt products
Platforms

## Plotting graph of 1/x

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))
Last edited by Persoontje; 19th February 2009 at 15:19.

Join Date
Aug 2008
Location
Algarve, Portugal
Posts
287
Thanks
23
Thanked 31 Times in 27 Posts
Qt products
Platforms

## Re: Plotting graph of 1/x

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).

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.