mirror of
https://github.com/Brandon-Rozek/website.git
synced 2025-05-19 04:52:28 +00:00
Fixed code in Octave Post
This commit is contained in:
parent
e63bbffaac
commit
a8526b57ba
1 changed files with 17 additions and 10 deletions
|
@ -30,30 +30,37 @@ First install [Octave](https://www.gnu.org/software/octave/) and the [symbolic p
|
||||||
|
|
||||||
Then in octave type in the following code
|
Then in octave type in the following code
|
||||||
|
|
||||||
|
```MATLAB
|
||||||
pkg load symbolic
|
pkg load symbolic
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
For every variable not defined earlier in your expression, make sure to declare it as a symbolic data type
|
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>
|
```MATLAB
|
||||||
|
syms x y
|
||||||
|
```
|
||||||
|
|
||||||
Then make an expression
|
Then make an expression
|
||||||
|
|
||||||
<pre class='language-MATLAB'><code class='language-MATLAB'>
|
```MATLAB
|
||||||
expr = y + sin(x)^2 + cos(x)^2
|
expr = y + sin(x)^2 + cos(x)^2
|
||||||
</code></pre>
|
```
|
||||||
|
|
||||||
You can then ask Octave to simplify the expression for you
|
You can then ask Octave to simplify the expression for you
|
||||||
|
|
||||||
<pre class='language-MATLAB'><code class='language-MATLAB'>
|
```MATLAB
|
||||||
simp_expr = simplify(expr)
|
simp_expr = simplify(expr)
|
||||||
</code></pre>
|
```
|
||||||
|
|
||||||
Displaying it shows it as
|
Displaying it shows it as
|
||||||
|
|
||||||
<pre class='language-MATLAB'><code class='language-MATLAB'>(sym) y + 1</code></pre>
|
```MATLAB
|
||||||
|
(sym) y + 1
|
||||||
|
```
|
||||||
|
|
||||||
Which is indeed a simplification using a trig identity 🙂
|
Which is indeed a simplification using a trig identity 🙂
|
||||||
|
|
||||||
|
Update: Octave's symbolic is based on [SymPy](https://www.sympy.org/en/index.html). If you're confortable with Python, I recommend checking it out.
|
||||||
|
|
Loading…
Add table
Reference in a new issue