MATLAB – Numerische Berechnung und Plots
MATLAB (MATrix LABoratory) ist eine proprietäre Sprache und Umgebung für numerische Berechnungen, Datenanalyse und Visualisierung. Grundlage ist die Arbeit mit Matrizen – fast jeder Befehl arbeitet vektorisiert, also auf ganzen Arrays gleichzeitig. Alternativen: Julia und Python mit NumPy/SciPy.
Grundbefehle
help <befehl>– Dokumentation anzeigendoc <befehl>– Dokumentationsfenster öffnenclc– Kommandozeile leerenclear– Variablen löschenwho / whos– Variablen auflistenformat long / format short– Zahlenformatdiary on / off– Session in Datei mitschreiben
Matrizen und Vektoren
v = [1 2 3] % Zeilenvektor
w = [1; 2; 3] % Spaltenvektor
A = [1 2; 3 4] % 2x2-Matrix
A' % Transponierte
A * B % Matrixmultiplikation
A .* B % elementweise Multiplikation
1:5 % [1 2 3 4 5]
linspace(0, 1, 11) % 11 Punkte von 0 bis 1
zeros(3), ones(2,4), eye(3), rand(3)
Programmierung
if ... elseif ... else ... endfor i = 1:10 ... endwhile bedingung ... endfunction [out] = name(in) ... end– in einer.m-Dateidisp(x)– Ausgabefprintf('Wert: %f ', x)– formatierte Ausgabe
Plots
plot(x, y) % Liniendiagramm
plot(x, y, 'r--') % Farbe/Linienstil
scatter(x, y) % Punktwolke
bar(x) % Balkendiagramm
histogram(x) % Histogramm
xlabel('x'), ylabel('y'), title('Titel')
legend('a', 'b')
grid on
subplot(2,1,1) % mehrere Plots in einer Figur
saveas(gcf, 'plot.png') % als Bild speichern
Weitere nützliche Funktionen
sum, mean, median, std, min, max– Statistikfind(A > 5)– Indizes von Elementensort, unique, reshape, transposefzero, fsolve, ode45– Nullstellen und DGL lösenfminsearch– Optimierungt = readtable('daten.csv'); plot(t)– Daten aus CSV laden
Verwandte Einträge: Julia, R und die Glossar-Einträge Array sowie Algorithmus.