~/Blog

Brandon Rozek

Photo of Brandon Rozek

PhD Student @ RPI studying Automated Reasoning in AI and Linux Enthusiast.

Simplifying Expressions with Octave

Published on

Updated on

Warning: This post has not been modified for over 2 years. For technical posts, make sure that it is still relevant.

Octave is a high level programming language intended for numerical computations. One of the cool features of this is that with symbolic expressions, you can then simplify mathematical expressions.

Setup

First install Octave and the symbolic package using the website or your package manager of choice.

Then in octave type in the following code

pkg load symbolic

Usage

For every variable not defined earlier in your expression, make sure to declare it as a symbolic data type

syms x y

Then make an expression

expr = y + sin(x)^2 + cos(x)^2

You can then ask Octave to simplify the expression for you

simp_expr = simplify(expr)

Displaying it shows it as

(sym) y + 1

Which is indeed a simplification using a trig identity 🙂

Update: Octave’s symbolic is based on SymPy. If you’re confortable with Python, I recommend checking it out.

Reply via Email Buy me a Coffee
Was this useful? Feel free to share: Hacker News Reddit Twitter

Published a response to this? :