Results 1 to 2 of 2

Thread: Plotting graph of 1/x

  1. #1
    Join Date
    Dec 2007
    Posts
    19
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

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

  2. #2
    Join Date
    Aug 2008
    Location
    Algarve, Portugal
    Posts
    287
    Thanks
    23
    Thanked 31 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

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

Similar Threads

  1. Graph plotting
    By steg90 in forum Qt Programming
    Replies: 13
    Last Post: 6th April 2011, 10:30
  2. Plotting from Left to Right ??
    By dheeraj in forum Qwt
    Replies: 3
    Last Post: 3rd June 2008, 07:09
  3. Plotting a graph with QWT
    By steg90 in forum Qwt
    Replies: 1
    Last Post: 6th June 2007, 17:04
  4. Threading and plotting graph in same program.
    By sar_van81 in forum Qt for Embedded and Mobile
    Replies: 2
    Last Post: 9th May 2007, 20:42
  5. regarding graph plotting in qt
    By sar_van81 in forum Qt for Embedded and Mobile
    Replies: 11
    Last Post: 30th April 2007, 08:51

Bookmarks

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.