1. Function Formula ⚓︎

Heart-Shaped Function Formula

y=(x2)13+0.9(3.3x2)12sin(nπx)y = \left(x^2\right)^{\frac{1}{3}} + 0.9 \cdot \left(3.3 - x^2\right)^{\frac{1}{2}} \cdot \sin(\mathbf{n} \pi x)

where n is a parameter, and the function graph changes as the value of n changes. The domain of the function is: [-1.81, 1.81]

2. Interactive Online Demo ⚓︎

Heart-shaped function graph
y = (x²)^(1/3) + 0.9 · (3.3 - x²)^(1/2) · sin(nπx)
Parameter n value 0.0
n = 0.0

3. Implementation in Excel ⚓︎

3.1 Step-by-Step Guide ⚓︎

  1. Variable x
    1. Create a new Excel spreadsheet, and enter X and Y in cells A1 and B1 respectively;
    2. Enter -1.81 in cell A2 (the left endpoint of the domain);
    3. Select cell A2, go to the Home tab, then find EditingFillSeries, open the dialog, select series in Columns, set step value to 0.01, and stop value to 1.81 (the right endpoint of the domain);
    4. This generates all possible values of the variable x for the function in column A.
  1. Variable y
    1. Enter the formula in cell B2: =(A2^2)^(1/3)+0.9*(3.3-A2^2)^(1/2)*SIN($D$2*PI()*A2), where cell D2 is the parameter n, and $D$2 is an absolute reference (F4 key);
    2. Select cell B2, move the mouse to the bottom-right corner of cell B2 until the pointer changes to a black cross (fill handle), then double-click the left mouse button to auto-fill the formula downward and calculate the corresponding y values for column A.
Formula
1
=(A2^2)^(1/3)+0.9*(3.3-A2^2)^(1/2)*SIN($D$2*PI()*A2)
  1. Create the Chart
    1. Select cell A1, press Ctrl + Shift + →, then press Ctrl + Shift + ↓ to select all data in columns A and B;
    2. Go to the Insert tab, find ChartsInsert Scatter (X, Y) or Bubble ChartScatter with Smooth Lines to create a heart-shaped scatter chart;
    3. Click the X-axis in the chart and press Delete to remove it; click the Y-axis and press Delete to remove it; also delete the chart title and legend.
  1. Iterative Calculation
    1. Enter the formula =D2+0.1 in cell D2 and press Enter;
    2. Select cell D2, click the File tab in the top-left corner of Excel, then select MoreOptionsFormulas at the bottom left;
    3. Under the Calculation options section on the right, check Enable iterative calculation, set Maximum iterations to 1, and click OK to save the settings;
    4. Hold down the F9 key (or Fn + F9 key) on the keyboard, and the heart-shaped function graph will begin a “beating” animation effect.

Result:

3.2 Excel Macro Code for Calculation Control ⚓︎

  • Open your Excel file, click the File tab in the top-left corner, select Save As, and set the save type to: Excel Macro-Enabled Workbook (*.xlsm).
  • Click the File tab in the top-left corner, select MoreOptionsCustomize Ribbon at the bottom left, check Developer under Customize the Ribbon on the right, and click OK to save.

(1) Form Control: Button ⚓︎

Click Developer, then click Visual Basic, and enter the following code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Public isLooping As Boolean
Public i As Double

Sub 心形图()
isLooping = Not isLooping
If isLooping Then
i = 0
Do While isLooping And i <= 1000
Range("D2").Value = i / 10
i = i + 1
DoEvents
If i Mod 1 = 0 Then
DoEvents
End If
Loop
isLooping = False
End If
End Sub

Insert a Form Control: Button, assign the macro 心形图 to it, click OK, and name the button 开关.

(2) Form Control: Start Button and Continuous Toggle ⚓︎

Click Developer, then click Visual Basic, and enter the following code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Public isLooping As Boolean
Public i As Double
Public continue As Boolean

Sub 心形图()
isLooping = Not isLooping
If isLooping Then
If Not continue Then
i = 0
End If
Do While isLooping And i <= 1000
Range("D2").Value = i / 10
i = i + 1
DoEvents
If i Mod 1 = 0 Then
DoEvents
End If
Loop
isLooping = False
End If
End Sub

Sub 连续开关()
continue = Not continue
End Sub

Insert a Form Control: Button, assign the macro 心形图 to it, click OK, and name the button 启动开关 for controlling start/stop;
Insert a Form Control: Button, assign the macro 连续开关 to it, click OK, and name the button 连续开关 for controlling whether parameter n runs continuously.

(3) ActiveX Control: Button ⚓︎

Insert an ActiveX Control: Button, enable Design Mode under the Developer tab, right-click the newly created button, select View Code, and enter the following code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Public isLooping As Boolean
Public i As Double

Private Sub CommandButton1_Click()
isLooping = Not isLooping
If isLooping Then
CommandButton1.Caption = "停止"
i = 0
Do While isLooping And i <= 1000
Range("D2").Value = i / 10
i = i + 1
DoEvents
If i Mod 1 = 0 Then
DoEvents
End If
Loop
isLooping = False
CommandButton1.Caption = "Start"
Else
isLooping = False
CommandButton1.Caption = "Start"
End If
End Sub

(4) Form Control: Scroll Bar ⚓︎

Insert a Form Control: Scroll Bar, right-click the scroll bar, select Format Control, and under the Control tab, set Minimum value: 0, Maximum value: 100, Incremental change: 1, and Cell link: $D$2.

(5) ActiveX Control: Scroll Bar ⚓︎

Insert an ActiveX Control: Scroll Bar, enable Design Mode under the Developer tab, right-click the newly created scroll bar, select View Code, and enter the following code:

1
2
3
Private Sub ScrollBar1_Change()
Range("D2") = ScrollBar1.Value / 10
End Sub

4. File Download ⚓︎

Click to Download