mirror of
https://github.com/Brandon-Rozek/website.git
synced 2024-11-22 16:26:28 -05:00
59 lines
2 KiB
Markdown
59 lines
2 KiB
Markdown
|
---
|
||
|
id: 2115
|
||
|
title: Simplifying Expressions with Octave
|
||
|
date: 2017-03-09T02:09:58+00:00
|
||
|
author: Brandon Rozek
|
||
|
layout: post
|
||
|
guid: https://brandonrozek.com/?p=2115
|
||
|
permalink: /2017/03/simplifying-expressions-octave/
|
||
|
medium_post:
|
||
|
- '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;}'
|
||
|
mf2_syndicate-to:
|
||
|
- 'a:1:{i:0;s:22:"bridgy-publish_twitter";}'
|
||
|
mf2_cite:
|
||
|
- '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:{}}'
|
||
|
tumblr_post_id:
|
||
|
- "158172999969"
|
||
|
mf2_syndication:
|
||
|
- 'a:1:{i:0;s:60:"https://twitter.com/B_RozekJournal/status/839659534146801665";}'
|
||
|
format: aside
|
||
|
kind:
|
||
|
- 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.
|
||
|
|
||
|
<!--more-->
|
||
|
|
||
|
## Setup
|
||
|
|
||
|
First install [Octave](https://www.gnu.org/software/octave/) and the [symbolic package](https://octave.sourceforge.io/symbolic/) 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
|
||
|
|
||
|
<pre class='language-MATLAB'><code class='language-MATLAB'>syms x y</code></pre>
|
||
|
|
||
|
Then make an expression
|
||
|
|
||
|
<pre class='language-MATLAB'><code class='language-MATLAB'>
|
||
|
expr = y + sin(x)^2 + cos(x)^2
|
||
|
</code></pre>
|
||
|
|
||
|
You can then ask Octave to simplify the expression for you
|
||
|
|
||
|
<pre class='language-MATLAB'><code class='language-MATLAB'>
|
||
|
simp_expr = simplify(expr)
|
||
|
</code></pre>
|
||
|
|
||
|
Displaying it shows it as
|
||
|
|
||
|
<pre class='language-MATLAB'><code class='language-MATLAB'>(sym) y + 1</code></pre>
|
||
|
|
||
|
Which is indeed a simplification using a trig identity 🙂
|