Octave (简体中文)
援引自Octave 官网:
- GNU Octave 是一种解释性的高级程序设计语言, 主要应用在数值计算领域。其拥有线性和非线性问题求解,以及执行其他数值分析的能力,还为数据可视化与数据操作提供了丰富的图形功能。 Octave通常的使用方式是交互式命令行,但其也可以用来编写非交互式程序。 Octave语言与Matlab非常相似,因此在两个平台编写的大部分程序都可以很容易移植。
Contents
安装
安装软件包 octave:
# pacman -S octave
打开GUI界面octave --gui
,或者打开命令行界面octave-cli
其他可供选择的图形界面
默认的 octave 图形界面 已经包含在了 octave 软件包中。除此之外,你还可以选择使用下列非官方的图形界面:
- Cantor — 一个图形用户界面,其后端的数学运算可以由以下软件之一提供 (Scilab, Maxima, Octave, R, Julia and others).
- JupyterLab — 一个基于浏览器的交互式环境,支持多种语言作为后端,也包括Octave。
- https://jupyter.org/lab[dead link 2020-04-01 ⓘ] || jupyterlab+jupyter-octave_kernelAUR
Octave-Forge
Octave提供一系列的外部包,类似于Matlab的工具箱, 参见 Octave-Forge.完整包列表参见这里.
这些外部包可以 #通过Octave自带安装器安装 或者 #通过AUR安装.
通过Octave自带安装器安装
外部包可以通过Octave自带安装器进行管理。 一般情况下他们会被安装到 ~/octave, 当使用-global
选项的时候会被安装到一个系统目录。
安装一个外部包
octave:1> pkg install -forge packagename
control
, 需要 gcc-fortran 包来进行编译和安装卸载一个外部包:
octave:3> pkg uninstall packagename
Some packages get loaded automatically by Octave, for those which do not:
octave:4> pkg load packagename
or
octave:5> pkg load all
To see which packages have been loaded use pkg list
, the packages with an asterisk are the ones that are already loaded.
A way to make sure that all packages gets loaded at Octave startup:
/usr/share/octave/site/m/startup/octaverc
## System-wide startup file for Octave. ## ## This file should contain any commands that should be executed each ## time Octave starts for every user at this site. pkg load all
通过AUR安装
Some packages may be found in the AUR (search packages). New Octave-forge packages for Arch can be created semi-automatically using the Octave-forge helper scripts for Archlinux.
Plotting
Qt is the default plotting backend:
>> available_graphics_toolkits ans = { [1,1] = fltk [1,2] = qt } >> graphics_toolkit ans = qt
Alternatively you can use either FLTK or Gnuplot backend (by installing gnuplot) and running the following command:
>> graphics_toolkit("gnuplot");
To make this change permanent add it to your ~/.octaverc
file.
Reading Microsoft Excel Spreadsheets
You can open .ods
, .xls
and .xlsx
files with the odsread
or xlsread
function, which requires the octave-ioAUR package:
octave:1> odsread('myfile.ods'); octave:1> xlsread('myfile.xls'); octave:1> xlsread('myfile.xlsx');
Converting to CSV format
Alternatively, first convert the files to .csv
using LibreOffice Calc (limited to 1024 columns) or Calligra Sheets (calligra, limited to 32768 columns).
After the conversion is complete you can use the build-in Octave function csvread
for .csv
files:
octave:1> csvread('myfile.csv');
Troubleshooting
Zsh Undecodable Token
If you get error
undecodable token: b(hex)[23m
when printing, install grml-zsh-config and relogin.
vi Mode Undecodable Token
Users with their .inputrc
configured for vi-mode, for example, as
~/.inputrc
$include /etc/inputrc set editing-mode vi $if mode=vi set show-mode-in-prompt on set vi-ins-mode-string \1\e[6 q\2 set vi-cmd-mode-string \1\e[2 q\2 set keymap vi-command # these are for vi-command mode Control-l: clear-screen Control-a: beginning-of-line set keymap vi-insert # these are for vi-insert mode Control-l: clear-screen Control-a: beginning-of-line $endif
may have the Octave GUI prompt corrupted as q>> undecodable token: \001b(hex)[6\0020(hex)
.
To remedy this, disable the show-mode-in-prompt
setting for Octave, by changing the above .inputrc
to be
~/.inputrc
$include /etc/inputrc set editing-mode vi $if mode=vi $if Octave set show-mode-in-prompt off $else set show-mode-in-prompt on set vi-ins-mode-string \1\e[6 q\2 set vi-cmd-mode-string \1\e[2 q\2 set keymap vi-command # these are for vi-command mode Control-l: clear-screen Control-a: beginning-of-line set keymap vi-insert # these are for vi-insert mode Control-l: clear-screen Control-a: beginning-of-line $endif $endif