Cubic Equation Solver: a Shiny App

Introduction

I majored in mathematics during my undergradute studies; I always have an interest in solving equations. Today, let’s talk about solving cubic equations of the form

$$ ax^3 + bx^2 + cx + d = 0, $$

where $a,\ b,\ c$ and $d$ are real numbers and $a\neq 0$. For this general cubic equation, there are two well-known (at least to some people) facts:
  1. The equation can be transformed into

$$ u^3 + pu + q = 0 $$

by first dividing $a$ on both sides of the original equation, and then letting

$$ x = u - \frac{b}{3a}. $$

  1. There is a closed-form (though somewhat complicated) formula for solving the transformed equation.

“Knowledge is power.” With the above facts, we can manually solve a cubic equation. However, if we actually carry out the process, the calculations can become quite tedious. So, I decided to build a Shiny app that can solve cubic equations.

Shiny app

The building process

I asked Microsoft 365 Copilot to write R code for me. I provided the AI with specific requirements—in particular, I asked it to produce exact solutions using symbolic operations. As a result, the generated R code uses the Python library sympy through the R package reticulate.

Lingyun Zhang (张凌云)
Lingyun Zhang (张凌云)
Design Analyst

I have research interests in Statistics, applied probability and computation.