2 Replies - 1129 Views - Last Post: 03 April 2011 - 06:21 PM Rate Topic: -----

#1 Googler20  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 01-April 11

VB 10

Posted 03 April 2011 - 03:32 PM

Hello, I Am working on a program.

     Dim xmax, xmin, ymax, ymin As Double                'globalize 

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim g As Graphics                               'to be able to draw the graph
        Dim PBlack As New Pen(Color.Black)              'pens to draw 
        Dim PCoral As New Pen(Color.Coral)
        Dim PBlue As New Pen(Color.SkyBlue)
        Dim sdBrush As SolidBrush = New SolidBrush(Color.Honeydew)
        Dim a, b As Double                              'declare variables for use
        Dim step1 As Double

        g = PictureBox1.CreateGraphics                  'to be able to draw the graph in the picture box

        xmin = 0                                        'set variables to range and domain of graph
        xmax = 1
        ymax = 1
        ymin = 0
        a = TextBox1.Text                               'for the user to imput values 
        b = TextBox2.Text
        step1 = 0.01
        g.Clear(Color.Gainsboro)                        'to clear the graph everytime user imputs new values

        For i = 0 To 1 Step step1                       'to compose the graph
            g.DrawLine(PCoral, xc(i), yc(f(i, a, B)/>), xc(i + step1), yc(f(i + step1, a, B)/>))

            g.DrawLine(PBlack, xc(0), yc(0), xc(1), yc(1))
            g.DrawLine(PBlack, xc(0), yc(0), xc(1), yc(0))
            g.DrawLine(PBlack, xc(0), yc(0), xc(0), yc(1))
        Next
        Dim output As String
        Dim x() As Double
        Dim n, T As Integer
        n = TextBox3.Text
        ReDim x(n)
        x(0) = TextBox3.Text
        output = ""

        For i = 1 To 100
            x(i) = f((x(i - 1)), a, B)/>

        Next

        For i = 0 To 100
            T = i + 1
            output = output & T & vbTab & x(i) & i & vbCrLf
        Next
        TextBox4.Text = output

        g.FillEllipse(sdBrush, xc(x(0)) - 2, yc(x(0)) - 2, 4, 4)


        For i = 0 To n - 1
            g.DrawLine(PBlue, xc(x(i)), yc(x(i)), xc(x(i)), yc(x(i + 1)))
            g.DrawLine(PBlue, xc(x(i)), yc(x(i + 1)), xc(x(i + 1)), yc(x(i + 1)))
        Next
    End Sub

    Function xc(ByVal x As Double) As Integer           'function to traslate into VB coordinates
        Return Int(400 * (x - xmin) / (xmax - xmin))
    End Function
    Function yc(ByVal y As Double) As Integer           'function to translate into VB coordinates
        Return Int(400 - 400 * (y - ymin) / (ymax - ymin))
    End Function
    Function g(ByVal x As Double, ByVal a As Double, ByVal b As Double) As Double       'function for use 
        Return -2 * x * x * x + 3 * (a + B)/> * x * x - 6 * a * b * x + 10
    End Function
    Function f(ByVal g As Double, ByVal max As Double, ByVal min As Double) As Double   'function for examination
        Return (g - min) / (max - min)
    End Function
    Function gprime(ByVal x As Double, ByVal a As Double, ByVal b As Double) As Double      'derivative of function g(x)
        Return -6 * x * x + 6 * (a + B)/> * x - 6 * a * b
    End Function
    Function mi(ByVal x As VariantType, ByVal y As VariantType) As VariantType           'function for min 
        If x > y Then
            mi = y
        Else
            mi = x
        End If
    End Function
    Function M(ByVal x As VariantType, ByVal y As VariantType) As VariantType           'function for max
        If x < y Then
            M = y
        Else
            M = x
        End If
    End Function
End Class 


This is it. I want the program to allow a user to enter parameters a and b. Then for the program to internally find the minumum and maximum of the function g(x)= -2x^3+3(a+b)x^2-6abx+10 on the interval (0,1).

But what I want is for the program to display the function f(x) = (g(x)- min)/(Max-min), and y=x, along with an array, and the dynamical system (chaos) with this function f(x).

I believe I have all the correct coding But I continually recieve an error and no graph is displayed in my picture box. The only thing displayed is y=x and my axis.

Does anyone have any suggestions on what it is im doing wrong? Or if my code is incorrect?

Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: VB 10

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8371
  • View blog
  • Posts: 31,101
  • Joined: 12-June 08

Re: VB 10

Posted 03 April 2011 - 05:47 PM

Okay - what error? What line? More information is required!
Was This Post Helpful? 0
  • +
  • -

#3 Googler20  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 01-April 11

Re: VB 10

Posted 03 April 2011 - 06:21 PM

View Postmodi123_1, on 03 April 2011 - 05:47 PM, said:

Okay - what error? What line? More information is required!



Sorry I forgot to add that!
My error is in the return line of this function
Function yc(ByVal y As Double) As Integer           'function to translate into VB coordinates
        Return Int(400 - 400 * (y - ymin) / (ymax - ymin))
    End Function


it says to ensure I am not dividing by zero, but I am not since my ymax is 1 and y min is 0. So I dont understand this error.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1