website/content/blog/2017-03-09-simplifying-expressions-octave.md

1.9 KiB

id title date author layout guid permalink medium_post mf2_syndicate-to mf2_cite tumblr_post_id mf2_syndication format kind
2115 Simplifying Expressions with Octave 2017-03-09T02:09:58+00:00 Brandon Rozek post https://brandonrozek.com/?p=2115 /2017/03/simplifying-expressions-octave/
O:11:"Medium_Post":11:{s:16:"author_image_url";N;s:10:"author_url";N;s:11:"byline_name";N;s:12:"byline_email";N;s:10:"cross_link";N;s:2:"id";N;s:21:"follower_notification";N;s:7:"license";N;s:14:"publication_id";N;s:6:"status";N;s:3:"url";N;}
a:1:{i:0;s:22:"bridgy-publish_twitter";}
a:4:{s:9:"published";s:25:"0000-01-01T00:00:00+00:00";s:7:"updated";s:25:"0000-01-01T00:00:00+00:00";s:8:"category";a:1:{i:0;s:0:"";}s:6:"author";a:0:{}}
158172999969
a:1:{i:0;s:60:"https://twitter.com/B_RozekJournal/status/839659534146801665";}
aside
note

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.