# Using Functions in Graphing

• ### 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

If CheckBox1.Checked Then
Else
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
If CheckBox3.Checked Then
Else
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()
Dim s As New Series
s.ChartType = SeriesChartType.Line

For i = 0 To UBound(Wx)

Next
s.Name = "W"
Beams_CHRT.Series.Clear()
Beams_CHRT.ResetAutoValues()
End Sub
End Class```

Sunday, May 25, 2014 6:38 PM

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

`        s.ChartType = SeriesChartType.Point`

jdweng

• Marked as answer by Tuesday, June 3, 2014 1:50 AM
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()

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

s.ChartType = SeriesChartType.Line
For i = 0 To UBound(Wx)

Next
s.Name = "W"
Beams_CHRT.Series.Clear()
Beams_CHRT.ResetAutoValues()

Dim a As New Series
a.ChartType = SeriesChartType.Line
For i = 0 To UBound(Wx)

Next
a.Name = "X"

Dim b As New Series
b.ChartType = SeriesChartType.Line
For i = 0 To UBound(Wx)

Next
b.Name = "YX"

Dim c As New Series
c.ChartType = SeriesChartType.Line
For i = 0 To UBound(Wx)

Next
c.Name = "Y"

Dim d As New Series
d.ChartType = SeriesChartType.Line
For i = 0 To UBound(Wx)

Next
d.Name = "Z"

End Sub
```

• Marked as answer by Tuesday, June 3, 2014 1:50 AM
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()

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

s.ChartType = SeriesChartType.Line
For i = 0 To UBound(Wx)

Next
s.Name = "W"
Beams_CHRT.Series.Clear()
Beams_CHRT.ResetAutoValues()

Dim a As New Series
a.ChartType = SeriesChartType.Line
For i = 0 To UBound(Wx)

Next
a.Name = "X"
Dim b As New Series
b.ChartType = SeriesChartType.Line
For i = 0 To UBound(Wx)

Next
b.Name = "Y"

Dim c As New Series
c.ChartType = SeriesChartType.Line
For i = 0 To UBound(Wx)

Next
c.Name = "Z"

Dim d As New Series
d.ChartType = SeriesChartType.Line
For i = 0 To UBound(Wx)

Next
d.Name = "A"

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```

• Marked as answer by Tuesday, June 3, 2014 1:50 AM
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

Beams_CHRT.Series.Clear()

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.Minimum = -1
End With

For chartindex = 0 To 4
Beams_CHRT.Series(chartindex).ChartType = DataVisualization.Charting.SeriesChartType.Line
Beams_CHRT.Series(chartindex).BorderWidth = 2
For i = 0 To UBound(Wx)
Next
Next

Beams_CHRT.Series(4).BorderDashStyle = ChartDashStyle.Dash

End Sub```

• Marked as answer by Tuesday, June 3, 2014 1:50 AM
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.

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

• Marked as answer by Tuesday, June 3, 2014 1:50 AM
Monday, May 26, 2014 12:12 PM
• It works for me. See the blue line at 100? That is your data from:

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()

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

s.ChartType = SeriesChartType.Line
For i = 0 To UBound(Wx)

Next
s.Name = "W"
Beams_CHRT.Series.Clear()
Beams_CHRT.ResetAutoValues()

Dim a As New Series
a.ChartType = SeriesChartType.Line
For i = 0 To UBound(Wx)

Next
a.Name = "X"

Dim b As New Series
b.ChartType = SeriesChartType.Line
For i = 0 To UBound(Wx)

Next
b.Name = "YX"

Dim c As New Series
c.ChartType = SeriesChartType.Line
For i = 0 To UBound(Wx)

Next
c.Name = "Y"

Dim d As New Series
d.ChartType = SeriesChartType.Line
For i = 0 To UBound(Wx)

Next
d.Name = "Z"

End Sub
```

• Marked as answer by Tuesday, June 3, 2014 1:50 AM
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()

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

s.ChartType = SeriesChartType.Line
For i = 0 To UBound(Wx)

Next
s.Name = "W"
Beams_CHRT.Series.Clear()
Beams_CHRT.ResetAutoValues()

Dim a As New Series
a.ChartType = SeriesChartType.Line
For i = 0 To UBound(Wx)

Next
a.Name = "X"
Dim b As New Series
b.ChartType = SeriesChartType.Line
For i = 0 To UBound(Wx)

Next
b.Name = "Y"

Dim c As New Series
c.ChartType = SeriesChartType.Line
For i = 0 To UBound(Wx)

Next
c.Name = "Z"

Dim d As New Series
d.ChartType = SeriesChartType.Line
For i = 0 To UBound(Wx)

Next
d.Name = "A"

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```

• Marked as answer by Tuesday, June 3, 2014 1:50 AM
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

Beams_CHRT.Series.Clear()

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.Minimum = -1
End With

For chartindex = 0 To 4