一说到数学方程,很多人就会马上联想到mathematica、MATLAB、mathCAD、maple等专业的数学软件,确实这四个软件是在科技和工程界上比较流行和著名,它们在各自针对的目标领域都有不同的特色。要是设计到专业的数学领域的问题当然就要用他们来解决,但是有时候我们的需求就只是想看看这个数学方程式的图像,这个时候就没有必要费力去安装破解体积这么庞大的软件,其实我们日常使用的Excel就能够担当大任!下面就来详细讲解一下作图思路和具体步骤:


先看一下最终的效果演示:

怎么用wps画方程的函数图像(无需专业数学软件)(1)

最终效果演示


步骤一:

新建一个工作表,命名为方程式和作图数据,并按如图所示填好相应的内容:

怎么用wps画方程的函数图像(无需专业数学软件)(2)

方程式表内容及参数填写

怎么用wps画方程的函数图像(无需专业数学软件)(3)

作图数据表格内容填写

步骤二:

打开VBE编辑器(Alt F11),或则在功能区打开,如下图所示:

怎么用wps画方程的函数图像(无需专业数学软件)(4)

打开VBE编辑器

插入一个模块,如下图所示:

怎么用wps画方程的函数图像(无需专业数学软件)(5)

插入一个模块

步骤三:

双击插入的模块(默认名称为:模块1),粘贴以下两段代码,代码的具体含义在这就不做详细讲解了,如有需要,欢迎交流,共同进步。

作图代码:

Sub 作图()

Dim obReg As Object

Dim oMatch As Object

Dim length As Integer

length = (Sheets("方程式").Cells(2, 3).Value - Sheets("方程式").Cells(2, 2).Value) / Sheets("方程式").Cells(2, 4).Value

Set obReg = CreateObject("vbscript.regexp")

Sheets("作图数据").Rows("2:1048576").Clear

Sheets("方程式").ChartObjects("图表 3").Activate '假设只有一个图表

With ActiveChart

For i = .SeriesCollection.Count To 1 Step -1

.SeriesCollection(i).Delete

Next

End With

With obReg

.Global = True

.IgnoreCase = True

.Pattern = "[x]"

End With

Sheets("作图数据").Cells(2, 1).FormulaR1C1 = "=方程式!R2C2"

Sheets("作图数据").Cells(3, 1).FormulaR1C1 = "=R[-1]C 方程式!R2C4"

Sheets("作图数据").Cells(3, 1).AutoFill Destination:=Sheets("作图数据").Range(Sheets("作图数据").Cells(3, 1), Sheets("作图数据").Cells(length 2, 1))

For i = 0 To 9

Sheets("作图数据").Cells(2, 2 i).FormulaR1C1 = "=" & obReg.Replace(Sheets("方程式").Cells(2 i, 1).Value, "RC[-" & i 1 & "]")

Sheets("作图数据").Range(Sheets("作图数据").Cells(2, 2 i), Sheets("作图数据").Cells(2, 2 i)).AutoFill Destination:=Sheets("作图数据").Range(Sheets("作图数据").Cells(2, 2 i), Sheets("作图数据").Cells(length 2, 2 i))

Next

ActiveWorkbook.Names.Add Name:="X_1", RefersToR1C1:="=OFFSET(作图数据!R1C1,0,0,方程式!R2C7,1)"

For j = 1 To 10

ActiveWorkbook.Names.Add Name:="Y_" & j, RefersToR1C1:="=OFFSET(作图数据!R1C" & j 1 & ",0,0,方程式!R2C7,1)"

Next

ActiveSheet.ChartObjects("图表 3").Activate

ActiveChart.SetSourceData Source:=Sheets("作图数据").Range("a1:b" & length 2)

For k = 2 To 10

Application.Goto Reference:="Y_" & k

Selection.Copy

Sheets("方程式").Select

ActiveSheet.ChartObjects("图表 3").Activate

ActiveChart.Paste

Next

Sheets("方程式").ChartObjects("图表 3").Activate

ActiveChart.Axes(xlValue).Select

ActiveChart.Axes(xlValue).MinimumScale = Sheets("方程式").Range("e2").Value

ActiveChart.Axes(xlValue).MaximumScale = Sheets("方程式").Range("f2").Value

ActiveChart.Axes(xlValue).MajorUnit = Sheets("方程式").Range("E5").Value

ActiveChart.Axes(xlValue).MinorUnit = Sheets("方程式").Range("F5").Value

ActiveChart.Axes(xlCategory).Select

ActiveChart.Axes(xlCategory).MinimumScale = Sheets("方程式").Range("b2").Value

ActiveChart.Axes(xlCategory).MaximumScale = Sheets("方程式").Range("c2").Value

ActiveChart.Axes(xlCategory).MajorUnit = Sheets("方程式").Range("C5").Value

ActiveChart.Axes(xlCategory).MinorUnit = Sheets("方程式").Range("D5").Value

End Sub

刷新代码:

Sub 刷新()

Dim obReg As Object

Dim oMatch As Object

Dim length As Integer

length = (Sheets("方程式").Cells(2, 3).Value - Sheets("方程式").Cells(2, 2).Value) / Sheets("方程式").Cells(2, 4).Value

Set obReg = CreateObject("vbscript.regexp")

Sheets("作图数据").Rows("2:1048576").Clear

With obReg

.Global = True

.IgnoreCase = True

.Pattern = "[x]"

End With

Sheets("作图数据").Cells(2, 1).FormulaR1C1 = "=方程式!R2C2"

Sheets("作图数据").Cells(3, 1).FormulaR1C1 = "=R[-1]C 方程式!R2C4"

Sheets("作图数据").Cells(3, 1).AutoFill Destination:=Sheets("作图数据").Range(Sheets("作图数据").Cells(3, 1), Sheets("作图数据").Cells(length 2, 1))

For i = 0 To 9

Sheets("作图数据").Cells(2, 2 i).FormulaR1C1 = "=" & obReg.Replace(Sheets("方程式").Cells(2 i, 1).Value, "RC[-" & i 1 & "]")

Sheets("作图数据").Range(Sheets("作图数据").Cells(2, 2 i), Sheets("作图数据").Cells(2, 2 i)).AutoFill Destination:=Sheets("作图数据").Range(Sheets("作图数据").Cells(2, 2 i), Sheets("作图数据").Cells(length 2, 2 i))

Next

ActiveWorkbook.Names.Add Name:="X_1", RefersToR1C1:="=OFFSET(作图数据!R1C1,0,0,方程式!R2C7,1)"

For j = 1 To 10

ActiveWorkbook.Names.Add Name:="Y_" & j, RefersToR1C1:="=OFFSET(作图数据!R1C" & j 1 & ",0,0,方程式!R2C7,1)"

Next

Sheets("方程式").ChartObjects("图表 3").Activate

ActiveChart.Axes(xlValue).Select

ActiveChart.Axes(xlValue).MinimumScale = Sheets("方程式").Range("e2").Value

ActiveChart.Axes(xlValue).MaximumScale = Sheets("方程式").Range("f2").Value

ActiveChart.Axes(xlValue).MajorUnit = Sheets("方程式").Range("E5").Value

ActiveChart.Axes(xlValue).MinorUnit = Sheets("方程式").Range("F5").Value

ActiveChart.Axes(xlCategory).Select

ActiveChart.Axes(xlCategory).MinimumScale = Sheets("方程式").Range("b2").Value

ActiveChart.Axes(xlCategory).MaximumScale = Sheets("方程式").Range("c2").Value

ActiveChart.Axes(xlCategory).MajorUnit = Sheets("方程式").Range("C5").Value

ActiveChart.Axes(xlCategory).MinorUnit = Sheets("方程式").Range("D5").Value

End Sub

步骤四:

在方程式表中插入两个宏按钮,具体操作如下:

怎么用wps画方程的函数图像(无需专业数学软件)(6)

插入按钮(窗体控件)

完成后效果如下:

怎么用wps画方程的函数图像(无需专业数学软件)(7)

完成效果图

步骤五:

将控件按钮分别对应关联到我们刚才粘贴的两段代码:

怎么用wps画方程的函数图像(无需专业数学软件)(8)

单击右键指定宏

怎么用wps画方程的函数图像(无需专业数学软件)(9)

关联对应的宏

步骤六:

大功告成!只需在方程式一栏中填写自己想要作图的方程然后点击作图即可生成函数图像。

注意:当改变X、Y轴范围时点击作图按钮,只是改变方程时点击刷新按钮!!!

怎么用wps画方程的函数图像(无需专业数学软件)(10)

注意事项

怎么用wps画方程的函数图像(无需专业数学软件)(11)

数学方程式图像


由于头条不能放置链接,如需要附件请私信我!


,