5

AngouriMath

 3 years ago
source link: https://am.angouri.org/research/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
icon_cropped.png

AngouriMath

Navigation

AngouriMath with F# for Research


128546739-f6bb078e-988d-4105-848e-f514f4e2e7fd.gif

AngouriMath.Interactive is suited for interactive computations and research, as it exposes a good amount of F# API. Basic functions include simplification, differentiation, latexisation (getting a LaTeX string from an expression), as well as solving equations, integrations, systems, working with vectors and matrices, etc.

Its main usage is notebooks, which are usable from Jupyter and Visual Studio Code notebooks extension. See dotnet/interactive to get notebooks working for you too.


Getting started


To get AngouriMath in your notebook, install it by running a so-called magic command:

#r "nuget:AngouriMath.Interactive,*-*"

Now, let's run a hello world:

open AngouriMath.FSharp.Functions
let x = symbol "x"
let a = symbol "a"
let expr = sin x + a
expr
128538783-522a22d3-ab2d-4009-b73e-60bf15ed885a.png

Let's find a derivative and integral over x, and their simplified versions:

derivative x expr + integral x expr
derivative x expr + integral x expr |> simplified
128539266-a6c2157b-5072-4a64-9bcd-972ced944bf8.png

Now, let's construct something more complex. For example, an equation:

let Omega_lambda = symbol "Omega_lambda"
let Omega_1 = symbol "Omega_1"
let eq = equality Omega_1 (sin Omega_lambda + sin (parsed 2 * Omega_lambda))
eq
128541799-38f22e17-69dd-49a0-bf21-b5eeaa117295.png

Let's find the solutions over Omega_lambda:

let roots = solutions Omega_lambda eq
roots
128542006-a829ef0d-f8e1-4a87-90de-89e6c23f6589.png

This is a set of roots, which is too huge for a screenshot. The only variable is Omega_1, so let's substitute it with a numeric value and evaluate the roots, showing them line by line with the default precision:

open AngouriMath
roots <|- (Omega_1, 0.3) |> evaled :?> Entity.Set.FiniteSet
|> Seq.map (fun el -> el.ToString()) |> String.concat "\n"
128542319-63f00725-85bd-46d0-a4ad-fbd817874eb3.png



Visualization


With the help of great plotting library Plotly.NET, it is possible to visualize functions over two and three variables.

vscnotebook.gif

Now, let's do some basic plotting. There is a few functions in the AngouriMath.Interactive namespace. Plot.linear and Plot.scatter visualizes single-variable functions:

open AngouriMath.Interactive
Plot.linear [ 0.0..0.01..3. ] "sin(x) + sin(2x) + sin(3x) + sin(4x)" 
128545928-7d61d546-de7a-4438-8e44-7fa79140e917.png

Now, let's display a surface, descriped by a function of two variables:

let f1 = parsed "sin(x) + sin(2x) + sin(3x) + sin(4x) + sin(5x)"
let f2 = parsed "cos(y) + sin(2y) + cos(3y) + sin(4y) + cos(5y)"
let z = f1 * f2
Plot.surface [ 0.0..0.01..3.5 ] [ 0.0..0.02..3.5 ] z
128546575-a56c8fab-0946-40eb-b9c8-28ebeb2d69ac.png

Plotting is available since 1.4.0-preview.1


Terminal


AngouriMath.Terminal is convenient CLI for interacting with functions without running a notebook, creating a file, etc. The commands ran in the terminal are in F# too.

terminal.gif

A nightly build can be downloaded from here. You need .NET 5 runtime (you only need the runtime ; no need for SDK).

Build from sources Or build it. Get .NET 5 SDK, then download it and build:
git close https://github.com/asc-community/AngouriMath
cd AngouriMath/Sources/Terminal/AngouriMath.Terminal
dotnet build -c release
and run:
dotnet run -c release

By default, there is a number of opened modules, such as AggressiveOperators, which override the default arithmetic operators. To see what is ran beforehand, type preRunCode.

It can be easily used as an advanced calculator too, not only as some professional tool.

2019-2021 Angouri · Project's repo · Site's repo · Octicons

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK