重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
1、利用公式求出Y值 第一列设置表头为x,下面依次填入取值, 比如 x 1 2 3 4 ...... 第二例表头设置为y,在下面表格中填入计算公式 如 =2*x+1 然后选中点右下角的十字型标记,拖下去,和前面x数量一致。 2、然后选中数据源(即选中要进行操作的数据区域,这里指XY值所在区域。) 3、执行菜单命令插入——图表——XY散点图 执行命令,打开图表向导对话框选XY散点图--选平滑线散点图--完成 最后使用图表向导在横坐标填入x值,纵坐标填入y值,生成图即可 将一次函数的Y列用公式编辑出来,分别填写出当取不同的X值时得到不的函数值,选择函数值所在列,插入——图表按提示操作。执行菜单命令 执行菜单命令
创新互联长期为成百上千家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为黄埔企业提供专业的做网站、成都网站设计,黄埔网站改版等技术服务。拥有10余年丰富建站经验和众多成功案例,为您定制开发。
VB系统的坐标原点在左上角,X轴的正方向是水平向右,而Y轴的正方向是垂直向下。所以,要绘制三角函数的曲线,自己可以通过改变点坐标的方法来实现,当然,VB.NET提供了相应的方法可以来实现坐标变换,也可以通过VB.Net的Graphics类提供的平移、旋转等转换来实现。
下面是我通过自己变换实现的示例,提供参考;我的环境是VB.NET 2010
Imports System.Math
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'1,获得一个Graphics对象
Dim MyGraphics As Graphics
MyGraphics = PictureBox1.CreateGraphics
'2,定义一个Pen对象,用于绘制图形(轮廓线)
Dim MyPen As New Pen(Color.Black, 1)
'3,定义一个Brush对象,用于填充图形(如果需要填充的话)
Dim MyBrush As New SolidBrush(Color.Orange)
MyGraphics.DrawLine(MyPen, 0, 200, 700, 200)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'1,获得一个Graphics对象
Dim MyGraphics As Graphics
MyGraphics = PictureBox1.CreateGraphics
'2,定义一个Pen对象,用于绘制图形(轮廓线)
Dim MyPen As New Pen(Color.Black, 1)
'3,定义一个Brush对象,用于填充图形(如果需要填充的话)
Dim MyBrush As New SolidBrush(Color.Orange)
'声明横向和纵向比例变量
Dim Heng As Integer = 20
Dim Zong As Integer = 50
'先获得正弦值,保存到点坐标数组
Dim MyPoints(700) As Point
Dim i As Integer
For i = 0 To 700
MyPoints(i) = New Point(i * Heng, 200 + Sin(i) * Zong)
Next
'采用绘制光滑线连接点的方式绘制曲线
MyGraphics.DrawCurve(MyPen, MyPoints)
End Sub
End Class
显示的效果图:
用vb画出简易函数图像的操作步骤为:
(1)新建一个工程,新建一个Form1,在上面添加一个picture控件和一个command控件;
(2)选中此控件,右击"复制",在窗体空白处右击"粘贴",在弹出的对话框中选择"是",创建了一个Command控件数组,复制,使窗体上总共出现7个Command控件;
(3)复制代码:
Const Pi = 3.1415926535 '定义圆周率
Dim a, wor
Dim i As Integer
Static Function Loge(X)
Loge = Log(X) / Log(Exp(1))
End Function
'定义用于在Picture1上的一个位置打印字符函数
Private Function PrintWord(X, y, Word As String)
With Picture1
.CurrentX = X
.CurrentY = y
.ForeColor = RGB(0, 0, 255)
End With
Picture1.Print Word
End Function
Private Function DrawDot(Px, Py, Color)
Picture1.PSet (Px, Py), Color
End Function
Sub XY() '建立直角坐标系
Picture1.DrawWidth = 1 '设置线条宽度
Picture1.Cls
'设定用户坐标系,坐标原点在Picture1中心
Picture1.Scale (-10, 10)-(10, -10)
Picture1.Line (-10, 0)-(10, 0), RGB(0, 0, 255)
Picture1.Line -(9.5, 0.5), RGB(0, 0, 255)
Picture1.Line (10, 0)-(9.5, -0.5), RGB(0, 0, 255)
Picture1.ForeColor = RGB(0, 0, 255)
Picture1.Print "X"
'画 X 轴
Picture1.Line (0, -10)-(0, 10), RGB(0, 0, 255)
Picture1.Line -(0.5, 9.5), RGB(0, 0, 255)
Picture1.Line (0, 10)-(-0.5, 9.5), RGB(0, 0, 255)
Picture1.Print "Y"
'画 Y 轴
For lin = -9 To 9
Picture1.Line (lin, 0)-(lin, 0.25)
wor = PrintWord(lin - 0.5, -0.5, Str(lin))
Picture1.Line (0, lin)-(-0.25, lin)
If lin 0 Then
wor = PrintWord(-0.9, lin, Str(lin))
End If
Next lin
Picture1.DrawWidth = 2
End Sub
Private Sub Command1_Click(Index As Integer)
Select Case Index
Case 0
For a = -3 To 3 Step Pi / 6000
Dot = DrawDot(a, a ^ 2, RGB(0, 0, 0))
Next a
wor = PrintWord(4, 9, "二次曲线 y=x^2")
Case 1
For a = -9 To 9 Step Pi / 6000
Dot = DrawDot(a, a, RGB(0, 0, 0))
Next a
wor = PrintWord(8, 5, "一次曲线 y=x")
Case 2
For a = -9 To 3 Step Pi / 6000
Dot = DrawDot(a, Exp(a), RGB(0, 0, 0))
Next a
wor = PrintWord(4, 9, "指数曲线 y=e^x")
Case 3
For a = 0.0001 To 9 Step Pi / 6000
Dot = DrawDot(a, Loge(a), RGB(0, 0, 0))
Next a
wor = PrintWord(8, 3, "对数曲线 y=ln x")
Case 4
For a = -10 To 10 Step Pi / 6000
Dot = DrawDot(a, Sin(a), RGB(0, 0, 0))
Next a
wor = PrintWord(-5, 2, "正弦曲线 y=sin x")
Case 5
For a = -10 To 10 Step Pi / 6000
Dot = DrawDot(a, Cos(a), RGB(0, 0, 0))
Next a
wor = PrintWord(-9, 2, "余弦曲线 y=cos x")
Case 6
XY
End Select
End Sub
Private Sub Form_Load()
Me.Caption = "数学函数作图?quot;"
Me.Show
Me.AutoRedraw = True
Picture1.AutoRedraw = True
Command1(0).Caption = "二次曲线"
Command1(1).Caption = "一次曲线"
Command1(2).Caption = "指数曲线"
Command1(3).Caption = "对数曲线"
Command1(4).Caption = "正弦曲线"
Command1(5).Caption = "余弦曲线"
Command1(6).Caption = "清空"
XY
End Sub
Private Sub Form_Resize()
Picture1.Width = Me.Width * 0.94
Picture1.Height = Me.Height - (Command1(0).Height * 4 + 100)
Command1(0).Top = Me.Height - (Command1(0).Height * 2.5 + 100)
Command1(0).Left = Me.Width * 0.01
For i = 1 To 6
Command1(i).Top = Me.Height - (Command1(0).Height * 2.5 + 100)
Command1(i).Left = Command1(i - 1).Left + 1000
Next
XY
End Sub