Home | Map

Wolfram Language

Béla Gyenes

Ways of accessing Wolfram Language

Currently, there are three main ways of accessing the Wolfram Language. The first very obvious one, is through Wolfram Mathematica. Then, we have the terminal option, where we use wolframscript on the terminal,to call the same functions as we would from Mathematica. Cloud services is also an option, but I won't be looking over that.

Mathematica

Mathematica is a program that has a really nice interface for the Wolfram Language. It is also a notebook-like program. You either pay for it, subscribe or get Mathematica on a trial. This brings us to our next point, using Wolfram Language from the terminal. wolframscript (which executes every time when running functions in either Mathematica, or cloud services) by default, is included in Mathematica.

Terminal

wolframscript executes every time when running functions in either Mathematica or the cloud based services. I'll be using terminal in this very instance, but I'll probably use it in the future, too.

By default, wolframscript is included in Mathematica. Specifically, it is under /usr/local/Wolfram/Mathematica/14.0/Executables/wolframscript on Linux. You can copy it from there, and paste it in /usr/local/bin/, or create a symlink for it the same way.

Basic Examples

Hello World

Outputting to screen is very simple.

Print["Hello, world!"]

Hello, world!

Basic Arithmetics

Addition, subtraction, etc. are straightforward, even newline \n characters work.

Print["This is addition of 2 + 2: ", 2+2, "\nAnd this is subtraction of the same: ", 2-2, "\nMultiplication: ", 2*2, "\nDivision: ", 2/2]

Hello, world! This is addition of 2 + 2: 4 And this is subtraction of the same: 0 Multiplication: 4 Division: 1

Symbolic Computation

Symbolic computation is one that emphasizes term rewriting over evaluation. Symbols (also called expressions) are rewritable terms, values imply a loss or an end to rewritability. In a way, symbols are more abstract, values more concrete

What's the answer to 3/9? A symbolic answer would be (a representation of) 1/3. A value answer would be 0.333333333 and so on, to however decimals we may want to write it.

Now, a symbolic computation (term rewriting) in Wolfram would go as follows:

Factor[x^2 - 1]

Which we would get the following, if we printed it out:

(-1 + x)*(1 + x)

Functions Definition

At function definitions in Wolframlang, we use colon equal signs. For example,

  • The notation f(x) := x means that the function of x is defined as x. Therefore, if we input the value 5, the output would also be 5.
  • Similarly, f(x) := x^2 means that the function f squares its input. Inputting 5 yields an output of 25.

In the context of Wolframlang, f[x_] is just another way to write f(x) in mathematical terms. At the very last line, we just print the output.

f[x_] := x^2
Print[f[5]]

25

Plotting

Basic Plotting

We use the Plot[] function in order to plot functions in Wolframlang.

plotty = Plot[x^2 - 2x - 3, {x, -5, 5}]
Export["Plotty.svg", plotty]
Plot[x^2 - 2x - 3, {x, -5, 5}]

First argument is the function (x2 - 2x - 3), second is a list {x, -5, 5}, with: variable (x), starting point (-5), stopping point (5) for the graph. We can see that the plot begins and ends at the points we specified it, -5 and 5. We set the whole plot as a "variable", and then we can export it.

sineplot = Plot[ Sin[x], {x, -7 Pi, 7 Pi} ]
Export["Sineplot.svg", sineplot]
Plot[ Sin[x], {x, -7 Pi, 7 Pi} ]

We set the beginning of the plot to -7 Pi, and the end of it to 7 Pi. Pi here means one amplitude. 7 Pi means 7 amplitudes in both directions.

Now, let's see an example of aspect ratios. An aspect ratio of 1 outputs the plot as a square picture, 2 gives outputs as height of 2 and width of 1. Aspect ratio in Wolframlang is as the follows: height : width. Quite the opposite from how it works in general. Let's see it in action:

aspectratio = Plot[ Sin[x], {x, -5, 5}, AspectRatio -> 2 ]
Export["a2.svg", aspectratio]
Plot[ Sin[x], {x, -5, 5}, AspectRatio -> 2 ]

This gives us the plot as elongated.

Multiple Plots

Wolframlang allows us to plot multiple functions at the same time. It automatically assigns colors to it, too! The first argument accepts a list of functions. The second argument is the usual range that we specify for our plot.

multi = Plot[ {Sin[x], Sin[2x], Sin[3x]}, {x, -Pi, Pi} ]
Export[ "multi.svg", multi ]
Plot[ {Sin[x], Sin[2x], Sin[3x]}, {x, -Pi, Pi} ]
  • First argument: {Sin[x], Sin[2x], Sin[3x]}
  • Second argument: {x, -Pi, Pi}

Advanced Overview

Below, we'll provide an advanced overview of the Wolfram Language. We'll look over: basic arithmetics, algebra, geometry, trigonometry, calculus, linear algebra, functions, plotting and graphing (1D, 2D, 3D).

Reusable String Templates

Simple Arithmetics

Print[ "1 + 2 = ", 1+2 ]
Print[ "4 - 3 = ", 4-3 ]
Print[ "2 * 3 = ", 2*3 ]
Print[ "8 / 2 = ", 8/2 ]
Print[ "2 ^ 3 = ", 2^3 ]

1 + 2 = 3 4 - 3 = 1 2 * 3 = 6 8 / 2 = 4 2 ^ 3 = 8

Geometry