Write a VBA code that will calculate and display the values of the given functio
ID: 3682339 • Letter: W
Question
Write a VBA code that will calculate and display the values of the given function f(x) = sin(x)/x for x where -5 x 5 with the increment of 0 1,i. E,Deltax=0.1. The VBA code should have a button (see the figure below), and this button should enable you to execute the followings, i. E., when you click this button, this program runs the followings: a) read the inputs from your worksheet,I_min I_min and Deltax from Cells E3,F3 and G3 (See the figure below). b) calculate and display x and f(x) in Columm B and C (See the figure below). From the calculated results (Columns B and C), graph x and f(x) (see the figure below) with labels for your axis and give the chart a title. You could plot manually, i. E., you do not need to have a functionality to plot by clicking the button. The program should read the x_min I_min and Deltax from Cells E3, F3 and G3 in Excel worksheet, respectively (You manually type the values of x_min x_min and Deltax in the worksheet, and see the figure below, and use range name) Write (or define) a function f(x) that would take an argument the x value as an input and return the corresponding y value, i. e., f(x) as an output. Submit a hard copy of your output, i. E., x and f(x) for each increment including the graph. Also submit a hardcopy of the source code. Comment your source code using the ' (single quotation mark) at the beginning of the line explaining the operation you are performing. At the top of your source code, add the following ME 325 -2016 Spring Hw #8 Name: ID: Description of the problemExplanation / Answer
I have written the VBA code for the same:
working code:
Option Explicit
Public c as Chart
Sub one()
Dim Row As Integer
Dim j As Single
Dim pi As Single
pi = 3.14159265359
Cells(1, 38).Value = "X"
j = -4 * pi
For Row = 2 To 82
Cells(Row, 38).Value = j
j = j + 0.025 * pi
Next Row
Cells(1, 39).Value = "SIN ( X )/X"
For Row = 2 To 82
Cells(Row, 39).Value = (Sin(Cells(Row, 38).Value))/Row
Next Row
Set c = ActiveWorkbook.Charts.Add
Set c = c.Location(where:=xlLocationAsObject, Name:="Sheet1")
With c
.ChartType = xlXYScatter
.Axes(xlValue).MajorGridlines.Delete
.Legend.Delete
End With
Dim cobject As ChartObject
Dim r As Range
Set cobject = ActiveSheet.ChartObjects(1)
Set r = ActiveSheet.Range(Cells(1, 1), Cells(37, 22))
cobject.Left = r.Left
cobject.Top = r.Top
cobject.Width = r.Width
cobject.Height = r.Height
Userform1.Show
End Sub
Private Sub CommandButton1_Click()
Dim sinx As Series
Set sinx = c.SeriesCollection.Add(Source:=Range(Cells(2, 38), Cells(82, 39)), _
CategoryLabels:=True)
With sinx
.Format.Fill.ForeColor.RGB = rgbBlack
c.SeriesCollection(1).MarkerSize = 2
End With
Me.Hide
End Sub
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.