Wednesday, January 25, 2012

Cubic Function Graph Plotter

This is a program that enables the user  to input the coefficients of a cubic function and draw its graph. The cubic function takes the form  f(x)=ax3+bx2+cx+d

The Code

Private Sub cmd_draw_Click()
Dim a, b, c, d As Integer
Dim w, v As Double
a = Val(txt_a.Text)
b = Val(txt_b.Text)
c = Val(txt_c.Text)
d = Val(txt_d.Text)
'Using a scale of 0.5 cm to represent i unit to draw the graph
' Need to make some transformation as the coordinates in VB start from top left

For w = 0 To 10 Step 0.001
v = a * (5 - w) ^ 3 + b * (5 - w) ^ 2 + c * (5 - w) + d
pic_graph.PSet (w, 5 - v)
Next w
End Sub

No comments: