none
Using Functions in Graphing RRS feed

  • Question

  • Hello, I am trying to make a Statics application where the user can input a point load located at the midpoint of the beam, a distributed load from 1/4 TO 3/4 of the beam or a Moment at 1/4 of the beam. I am having trouble getting the various Force, Shear, Moment, Angle, and Deflection Diagrams to plot, which are represented by Wx(I) from 0 to 4 respectively.
    Imports System.Drawing
    Imports System.Windows.Forms.DataVisualization.Charting
    Imports System.Math
    Imports System.Drawing.Drawing2D
    Public Class Beams
        Public Wx(4, 1000) As Double
        
        Function Singularity(ByVal x As Double, ByVal n As Double, ByVal a As Double) As Double
            If n < 0 Then
                Return 0
            ElseIf x - a < 0 Then
                Return 0
            Else
                Return (x - a) ^ n
            End If
        End Function
    
        Function ptload() As Double
            Dim Load As Double
            If CheckBox1.Checked Then
                Load = TextBox1.Text
            Else
                Load = 0
            End If
            Dim L As Double = 100
            Dim loc As Double = 50
            For i = 0 To UBound(Wx, 2)
                Wx(0, i) = Wx(0, i) + Load * (Singularity(i * L / UBound(Wx, 2), -1, loc))
                Wx(1, i) = Wx(1, i) + Load * (Singularity(i * L / UBound(Wx, 2), 0, loc))
                Wx(2, i) = Wx(2, i) + Load * (Singularity(i * L / UBound(Wx, 2), 1, loc))
                Wx(3, i) = Wx(3, i) + Load * (Singularity(i * L / UBound(Wx, 2), 2, loc)) / 2
                Wx(4, i) = Wx(4, i) + Load * (Singularity(i * L / UBound(Wx, 2), 3, loc)) / 6
            Next
    
        End Function
        Function distrload() As Double
            Dim Load As Double
            If CheckBox3.Checked Then
                Load = TextBox3.Text
            Else
                Load = 0
            End If
            Dim L As Double = 100
            Dim loc As Double
            For i = 0 To UBound(Wx, 2)
                Wx(0, i) = Wx(0, i) + Load * (Singularity(i * L / UBound(Wx, 2), 0, loc))
                Wx(1, i) = Wx(1, i) + Load * (Singularity(i * L / UBound(Wx, 2), 1, loc))
                Wx(2, i) = Wx(2, i) + Load * (Singularity(i * L / UBound(Wx, 2), 2, loc)) / 2
                Wx(3, i) = Wx(3, i) + Load * (Singularity(i * L / UBound(Wx, 2), 3, loc)) / 6
                Wx(4, i) = Wx(4, i) + Load * (Singularity(i * L / UBound(Wx, 2), 4, loc)) / 24
            Next
    
        End Function
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            Beams_CHRT.Series.Clear()
            Beams_CHRT.Titles.Clear()
            Beams_CHRT.Titles.Add("Force")
            Dim s As New Series
            distrload()
            ptload()
            s.ChartType = SeriesChartType.Line
    
            For i = 0 To UBound(Wx)
    
                s.Points.AddXY(i, 100)
            Next
            s.Name = "W"
            Beams_CHRT.Series.Clear()
            Beams_CHRT.ResetAutoValues()
            Beams_CHRT.Series.Add(s)
        End Sub
    End Class

    Sunday, May 25, 2014 6:38 PM

Answers

  • Try a point chart instead of a line.  You results are not linear.

            s.ChartType = SeriesChartType.Point


    jdweng

    Monday, May 26, 2014 12:12 PM
  • Here I put in wx with 4 series. Note I removed the Beams_CHRT.Series.Clear you have at the end.

        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            Beams_CHRT.Series.Clear()
            Beams_CHRT.Titles.Clear()
            Beams_CHRT.Titles.Add("Force")
    
            With Beams_CHRT.ChartAreas(0)
                .AxisX.MajorGrid.Enabled = True
                .AxisX.MajorGrid.LineColor = Color.LightGray
                .AxisX.LabelStyle.Enabled = True
                .AxisY.MajorGrid.Enabled = True
                .AxisY.MajorGrid.LineColor = Color.LightGray
                .AxisY.LabelStyle.Enabled = True
            End With
            Dim s As New Series
    
            distrload()
            ptload()
    
            s.ChartType = SeriesChartType.Line
            For i = 0 To UBound(Wx)
    
                s.Points.AddXY(i, Wx(0, i))
            Next
            s.Name = "W"
            Beams_CHRT.Series.Clear()
            Beams_CHRT.ResetAutoValues()
            Beams_CHRT.Series.Add(s)
    
            Dim a As New Series
            a.ChartType = SeriesChartType.Line
            For i = 0 To UBound(Wx)
    
                a.Points.AddXY(i, Wx(1, i))
            Next
            a.Name = "X"
            Beams_CHRT.Series.Add(a)
    
            Dim b As New Series
            b.ChartType = SeriesChartType.Line
            For i = 0 To UBound(Wx)
    
                b.Points.AddXY(i, Wx(2, i))
            Next
            b.Name = "YX"
            Beams_CHRT.Series.Add(b)
    
            Dim c As New Series
            c.ChartType = SeriesChartType.Line
            For i = 0 To UBound(Wx)
    
                c.Points.AddXY(i, Wx(3, i))
            Next
            c.Name = "Y"
            Beams_CHRT.Series.Add(c)
    
            Dim d As New Series
            d.ChartType = SeriesChartType.Line
            For i = 0 To UBound(Wx)
    
                d.Points.AddXY(i, Wx(4, i))
            Next
            d.Name = "Z"
            Beams_CHRT.Series.Add(d)
    
        End Sub
    

    Monday, May 26, 2014 2:24 PM
  • I added some visuals to make it easier to see.

        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            Beams_CHRT.Series.Clear()
            Beams_CHRT.Titles.Clear()
            Beams_CHRT.Titles.Add("Force")
    
            With Beams_CHRT.ChartAreas(0)
                .AxisX.MajorGrid.Enabled = True
                .AxisX.MajorGrid.LineColor = Color.LightGray
                .AxisX.LabelStyle.Enabled = True
                .AxisY.MajorGrid.Enabled = True
                .AxisY.MajorGrid.LineColor = Color.LightGray
                .AxisY.LabelStyle.Enabled = True
    
                .AxisY.Minimum = -1
    
            End With
            Dim s As New Series
    
            distrload()
            ptload()
    
            s.ChartType = SeriesChartType.Line
            For i = 0 To UBound(Wx)
    
                s.Points.AddXY(i, Wx(0, i))
            Next
            s.Name = "W"
            Beams_CHRT.Series.Clear()
            Beams_CHRT.ResetAutoValues()
            Beams_CHRT.Series.Add(s)
    
            Dim a As New Series
            a.ChartType = SeriesChartType.Line
            For i = 0 To UBound(Wx)
    
                a.Points.AddXY(i, Wx(1, i))
            Next
            a.Name = "X"
            Beams_CHRT.Series.Add(a)
            Dim b As New Series
            b.ChartType = SeriesChartType.Line
            For i = 0 To UBound(Wx)
    
                b.Points.AddXY(i, Wx(2, i))
            Next
            b.Name = "Y"
            Beams_CHRT.Series.Add(b)
    
            Dim c As New Series
            c.ChartType = SeriesChartType.Line
            For i = 0 To UBound(Wx)
    
                c.Points.AddXY(i, Wx(3, i))
            Next
            c.Name = "Z"
            Beams_CHRT.Series.Add(c)
    
            Dim d As New Series
            d.ChartType = SeriesChartType.Line
            For i = 0 To UBound(Wx)
    
                d.Points.AddXY(i, Wx(4, i))
            Next
            d.Name = "A"
            Beams_CHRT.Series.Add(d)
    
            Beams_CHRT.Series(0).BorderWidth = 2
            Beams_CHRT.Series(1).BorderWidth = 2
            Beams_CHRT.Series(2).BorderWidth = 2
            Beams_CHRT.Series(3).BorderWidth = 2
            Beams_CHRT.Series(4).BorderWidth = 2
    
        End Sub

    Monday, May 26, 2014 2:46 PM
  • Here is an example with a loop.

        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            Dim headings(4) As String
            headings = Split("Load Shear Moment Deflection Angle")
    
            Beams_CHRT.Series.Clear()
            Beams_CHRT.Titles.Add("Force")
    
            With Beams_CHRT.ChartAreas(0)
                .AxisX.MajorGrid.Enabled = True
                .AxisX.MajorGrid.LineColor = Color.LightGray
                .AxisX.LabelStyle.Enabled = True
                .AxisX.Title = "Span"
    
                .AxisY.MajorGrid.Enabled = True
                .AxisY.MajorGrid.LineColor = Color.LightGray
                .AxisY.LabelStyle.Enabled = True
                .AxisY.Title = "Load"
                .AxisY.Minimum = -1
            End With
    
            distrload()
            ptload()
    
            For chartindex = 0 To 4
                Beams_CHRT.Series.Add(CStr(chartindex) & " " & headings(chartindex))
                Beams_CHRT.Series(chartindex).ChartType = DataVisualization.Charting.SeriesChartType.Line
                Beams_CHRT.Series(chartindex).BorderWidth = 2
                For i = 0 To UBound(Wx)
                    Beams_CHRT.Series(chartindex).Points.AddXY(i, Wx(chartindex, i))
                Next
            Next
    
            Beams_CHRT.Series(4).BorderDashStyle = ChartDashStyle.Dash
    
        End Sub

    Monday, May 26, 2014 11:07 PM

All replies

  • Hi Newtoprogramming345,

    Since it is related to the VB language development, I am moving your thread into the Visual Basic Forum for dedicated support.

    Best Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, May 26, 2014 11:41 AM
  • Try a point chart instead of a line.  You results are not linear.

            s.ChartType = SeriesChartType.Point


    jdweng

    Monday, May 26, 2014 12:12 PM
  • It works for me. See the blue line at 100? That is your data from:

    s.Points.AddXY(i, 100)

    Did you want to plot Wx()?

    Monday, May 26, 2014 2:02 PM
  • Here I put in wx with 4 series. Note I removed the Beams_CHRT.Series.Clear you have at the end.

        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            Beams_CHRT.Series.Clear()
            Beams_CHRT.Titles.Clear()
            Beams_CHRT.Titles.Add("Force")
    
            With Beams_CHRT.ChartAreas(0)
                .AxisX.MajorGrid.Enabled = True
                .AxisX.MajorGrid.LineColor = Color.LightGray
                .AxisX.LabelStyle.Enabled = True
                .AxisY.MajorGrid.Enabled = True
                .AxisY.MajorGrid.LineColor = Color.LightGray
                .AxisY.LabelStyle.Enabled = True
            End With
            Dim s As New Series
    
            distrload()
            ptload()
    
            s.ChartType = SeriesChartType.Line
            For i = 0 To UBound(Wx)
    
                s.Points.AddXY(i, Wx(0, i))
            Next
            s.Name = "W"
            Beams_CHRT.Series.Clear()
            Beams_CHRT.ResetAutoValues()
            Beams_CHRT.Series.Add(s)
    
            Dim a As New Series
            a.ChartType = SeriesChartType.Line
            For i = 0 To UBound(Wx)
    
                a.Points.AddXY(i, Wx(1, i))
            Next
            a.Name = "X"
            Beams_CHRT.Series.Add(a)
    
            Dim b As New Series
            b.ChartType = SeriesChartType.Line
            For i = 0 To UBound(Wx)
    
                b.Points.AddXY(i, Wx(2, i))
            Next
            b.Name = "YX"
            Beams_CHRT.Series.Add(b)
    
            Dim c As New Series
            c.ChartType = SeriesChartType.Line
            For i = 0 To UBound(Wx)
    
                c.Points.AddXY(i, Wx(3, i))
            Next
            c.Name = "Y"
            Beams_CHRT.Series.Add(c)
    
            Dim d As New Series
            d.ChartType = SeriesChartType.Line
            For i = 0 To UBound(Wx)
    
                d.Points.AddXY(i, Wx(4, i))
            Next
            d.Name = "Z"
            Beams_CHRT.Series.Add(d)
    
        End Sub
    

    Monday, May 26, 2014 2:24 PM
  • I added some visuals to make it easier to see.

        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            Beams_CHRT.Series.Clear()
            Beams_CHRT.Titles.Clear()
            Beams_CHRT.Titles.Add("Force")
    
            With Beams_CHRT.ChartAreas(0)
                .AxisX.MajorGrid.Enabled = True
                .AxisX.MajorGrid.LineColor = Color.LightGray
                .AxisX.LabelStyle.Enabled = True
                .AxisY.MajorGrid.Enabled = True
                .AxisY.MajorGrid.LineColor = Color.LightGray
                .AxisY.LabelStyle.Enabled = True
    
                .AxisY.Minimum = -1
    
            End With
            Dim s As New Series
    
            distrload()
            ptload()
    
            s.ChartType = SeriesChartType.Line
            For i = 0 To UBound(Wx)
    
                s.Points.AddXY(i, Wx(0, i))
            Next
            s.Name = "W"
            Beams_CHRT.Series.Clear()
            Beams_CHRT.ResetAutoValues()
            Beams_CHRT.Series.Add(s)
    
            Dim a As New Series
            a.ChartType = SeriesChartType.Line
            For i = 0 To UBound(Wx)
    
                a.Points.AddXY(i, Wx(1, i))
            Next
            a.Name = "X"
            Beams_CHRT.Series.Add(a)
            Dim b As New Series
            b.ChartType = SeriesChartType.Line
            For i = 0 To UBound(Wx)
    
                b.Points.AddXY(i, Wx(2, i))
            Next
            b.Name = "Y"
            Beams_CHRT.Series.Add(b)
    
            Dim c As New Series
            c.ChartType = SeriesChartType.Line
            For i = 0 To UBound(Wx)
    
                c.Points.AddXY(i, Wx(3, i))
            Next
            c.Name = "Z"
            Beams_CHRT.Series.Add(c)
    
            Dim d As New Series
            d.ChartType = SeriesChartType.Line
            For i = 0 To UBound(Wx)
    
                d.Points.AddXY(i, Wx(4, i))
            Next
            d.Name = "A"
            Beams_CHRT.Series.Add(d)
    
            Beams_CHRT.Series(0).BorderWidth = 2
            Beams_CHRT.Series(1).BorderWidth = 2
            Beams_CHRT.Series(2).BorderWidth = 2
            Beams_CHRT.Series(3).BorderWidth = 2
            Beams_CHRT.Series(4).BorderWidth = 2
    
        End Sub

    Monday, May 26, 2014 2:46 PM
  • Here is an example with a loop.

        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            Dim headings(4) As String
            headings = Split("Load Shear Moment Deflection Angle")
    
            Beams_CHRT.Series.Clear()
            Beams_CHRT.Titles.Add("Force")
    
            With Beams_CHRT.ChartAreas(0)
                .AxisX.MajorGrid.Enabled = True
                .AxisX.MajorGrid.LineColor = Color.LightGray
                .AxisX.LabelStyle.Enabled = True
                .AxisX.Title = "Span"
    
                .AxisY.MajorGrid.Enabled = True
                .AxisY.MajorGrid.LineColor = Color.LightGray
                .AxisY.LabelStyle.Enabled = True
                .AxisY.Title = "Load"
                .AxisY.Minimum = -1
            End With
    
            distrload()
            ptload()
    
            For chartindex = 0 To 4
                Beams_CHRT.Series.Add(CStr(chartindex) & " " & headings(chartindex))
                Beams_CHRT.Series(chartindex).ChartType = DataVisualization.Charting.SeriesChartType.Line
                Beams_CHRT.Series(chartindex).BorderWidth = 2
                For i = 0 To UBound(Wx)
                    Beams_CHRT.Series(chartindex).Points.AddXY(i, Wx(chartindex, i))
                Next
            Next
    
            Beams_CHRT.Series(4).BorderDashStyle = ChartDashStyle.Dash
    
        End Sub

    Monday, May 26, 2014 11:07 PM