A parametric view of love


If you tell my wife that she's married to a statistical geek, she'll nod knowingly. She is used to hearing sweet words of affection such as

You are more beautiful than Euler's identity.
My love for you is like the exponential function: increasing, unbounded, and transcendental.

But those are ordinary, everyday sentiments. For Valentine's Day, I want to do something really special, such as formulating a parametric expression whose image is heart-shaped. If you haven't gotten anything sweet for your special someone, you too can use SAS/IML Studio to create the following image!

Modify the program to create your own personal message. My personal message to my wife is "I love you."

/** Valentine's Day heart. Rick Wicklin: blogs.sas.com/content/iml **/
/** Parametrize in polar coordinates h(t) = (r(t), theta(t)) **/
Pi = constant("Pi");
t = do(0, 2*Pi, 0.01*Pi/4)`;
r = 2 - 2*sin(t) + sin(t)#sqrt(abs(cos(t))) / (sin(t)+1.4);
/** Convert to Euclidean coordinates for plotting **/
x = r#cos(t);
y = r#sin(t);
/** Use SAS/IML Studio to produce the image **/
declare DataObject dobj;
dobj = DataObject.Create("Valentine", {"x" "y"}, x||y );
dobj.AddVar("const", j(nrow(t),1));
dobj.SetMarkerFillColor(OBS_ALL, RED);
declare PolygonPlot p;
p = PolygonPlot.Create(dobj, "x", "y", "const", true);
"r = 2 - 2*sin(t) + sin(t)*sqrt(|cos(t)|) / (sin(t)+1.4)");

About Author

Rick Wicklin

Distinguished Researcher in Computational Statistics

Rick Wicklin, PhD, is a distinguished researcher in computational statistics at SAS and is a principal developer of PROC IML and SAS/IML Studio. His areas of expertise include computational statistics, simulation, statistical graphics, and modern methods in statistical data analysis. Rick is author of the books Statistical Programming with SAS/IML Software and Simulating Data with SAS.


  1. Yes, that’s a good one!

    Your solution implicitly defines the curve as the level set of a surface, whereas mine is a parameterized curve. I wanted my heart to have sharp points at the middle and bottom of the heart. This is easier to do with a parametric curve than with an implicitly defined curve.

    Contouring algorithms often incorrectly represent the level set of a surface when the surface is tangent to the cutting plane. A classic example is the level set (x-alpha)^2-(y-beta)^2=0, which is supposed to be two lines that intersect at (alpha, beta). Contouring algorithms often represent this level set as two almost-touching hyperbolas.

    Notice in your example that the implicit curve as computed by Wolfram Alpha is "rounded" at (0, +/-15/sqrt(17)), whereas a correct representation of the curve would be "pointed" there.

  2. Well .. I'm not much of a math person ... but I read this on a bathroom stall at a rest stop between Kentucky and Tennessee in fourth grade - and it's still good! Plus I'm sure of the math.

    2 lovers
    + 2 gether

    I read some other things that I won't share. But there are a lot of cheatin' boyfriends and little daVincis with magic markers out there! I'm just saying. :-)

  3. Pingback: Belated code - SAS Users Groups

  4. Pingback: Binary heart in SAS - The DO Loop

Leave A Reply

Back to Top