drawing of functional graphs

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tiyantra cosmas
    New Member
    • Nov 2011
    • 1

    drawing of functional graphs

    how can i draw a graph of a function using visual basic.net 2010? eg graph of y=cos2x +5x
  • Crusader2010
    New Member
    • Nov 2011
    • 13

    #2
    Basically you need to look up the System.Drawing. Graphics class on how to draw lines and points from code. After that simply create 2 perpendicular axes. Your function should look something like:

    Code:
    Public Function y(byval x as double) as double
      Return (5*x) + Math.Cos(2*x)
    End Function
    If you happen to pass degrees don't forget to convert them to radians before, x*Math.pi/180. Now you can give values to your function (for example in a loop incrementing x by 0.01 or something) and drawing lines between two successive points. Use as reference the two axes you drawn before.

    If you want arcs (and a more fluid graph) you'll need to compute slopes and such, but you can avoid these computations by giving very very small increments to "x" and drawing lines ;) Basically any curve can be approximated as successive lines made between points very close together (check Darboux integrals, if i remember correctly).

    I don't know if there are better way to do this (and they could very well be), but i hope i pointed you in the right direction.

    Comment

    Working...