0% fanden dieses Dokument nützlich (0 Abstimmungen)
76 Ansichten67 Seiten

Matlab SS2022 Teil 01

Das Dokument ist ein Skript zur Simulation adaptronischer Systeme mit MATLAB und Simulink, das im Sommersemester 2022 von Prof. Dr.-Ing. Sinapius und Dr.-Ing. Naser Al Natsheh bereitgestellt wird. Es enthält organisatorische Informationen, eine Einführung in MATLAB, grundlegende Funktionen, sowie Anleitungen zur Nutzung von MATLAB und Simulink für die Modellierung und Simulation dynamischer Systeme. Zudem werden empfohlene Literaturquellen und Kontaktinformationen für die Dozenten bereitgestellt.

Hochgeladen von

成瑾才
Copyright
© © All Rights Reserved
Wir nehmen die Rechte an Inhalten ernst. Wenn Sie vermuten, dass dies Ihr Inhalt ist, beanspruchen Sie ihn hier.
Verfügbare Formate
Als PDF, TXT herunterladen oder online auf Scribd lesen
0% fanden dieses Dokument nützlich (0 Abstimmungen)
76 Ansichten67 Seiten

Matlab SS2022 Teil 01

Das Dokument ist ein Skript zur Simulation adaptronischer Systeme mit MATLAB und Simulink, das im Sommersemester 2022 von Prof. Dr.-Ing. Sinapius und Dr.-Ing. Naser Al Natsheh bereitgestellt wird. Es enthält organisatorische Informationen, eine Einführung in MATLAB, grundlegende Funktionen, sowie Anleitungen zur Nutzung von MATLAB und Simulink für die Modellierung und Simulation dynamischer Systeme. Zudem werden empfohlene Literaturquellen und Kontaktinformationen für die Dozenten bereitgestellt.

Hochgeladen von

成瑾才
Copyright
© © All Rights Reserved
Wir nehmen die Rechte an Inhalten ernst. Wenn Sie vermuten, dass dies Ihr Inhalt ist, beanspruchen Sie ihn hier.
Verfügbare Formate
Als PDF, TXT herunterladen oder online auf Scribd lesen

Platzhalter für Bild, Bild auf Titelfolie hinter das Logo einsetzen

Simulation adaptronischer Systeme mit


MATLAB® / Simulink®
SS 2022
Prof. Dr.-Ing. Sinapius, Dr.-Ing. Naser Al Natsheh
Copyright

Dieses Skript unterliegt dem deutschen Urheberrecht. Es darf nur zum persönlichen Gebrauch zu
Zwecken des Studiums verwendet werden. Insbesondere ist es nicht erlaubt, das Skript oder Teile
daraus zu bearbeiten, zu übersetzen, zu kopieren oder in elektronischer Form zu speichern und an
andere Personen weiterzugeben, weder in Kopie, noch auf elektronischem Wege per Email, auf
Speichermedien (z. B. CD, USB-Stick usw.), über Datenbanken oder andere Medien und Systeme.
Lediglich die Herstellung von Kopien und Downloads für den persönlichen, privaten und nicht
kommerziellen Gebrauch ist erlaubt.

This script is subject to German copyright law. It is restricted to personal use for the purpose of
studying. In particular it is not allowed to edit the script or parts of it, to translate, copy or save it in
electronic form and to pass it on to other people, neither as a copy nor electronically via email, data
storage media (e.g., CD, USB flash drive, etc.), databases or other media and systems. Only the
production of copies and downloads for personal, private and noncommercial use is permitted.

19. April 2022 | Sinapius | Al Natsheh


Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 2
Inhaltsverzeichnis
Thema Seite Thema Seite
Organisatorisches 4 Stiloptionen im plot-Befehl 143
Einführung in MATLAB Weiterführende Funktionen des plot-Befehls 151
Empfohlene Literatur 10 Einbindung von Matlab-plots in Latex: Matlab2Tikz 179
MATLAB Grundlagen, Hilfefunktion, einfache Befehle 14 Koordinatentransformationen 190
Nützliche Befehle 27 Nutzung von Subplots 193
Eingabe, Verarbeitung und Analyse von Matrizen 29 Sonderzeichen 199
Lineare Algebra, Eigenwertprobleme 63 Differentialgleichungen in MATLAB
Nutzung von Skripten 71 Lösung gewöhnlicher Differentialgleichungen 202
Rechnen mit komplexen Zahlen 93 Übersicht verschiedener Lösungsalgorithmen 212
Eingabe und Verarbeitung von Polynomen 98 Ein- und Ausgabe in MATLAB
Funktionen in MATLAB 105 Allgemeines zu Ein- und Ausgaben 240
Nutzung logischer Operatoren 113 Formatierte Ausgaben 247
Schleifen und Verzweigungen in MATLAB Einführung in Simulink
If-Anweisung 120 Einführung in Simulink 250
Switch-Anweisung 122 Lösung von Differentialgleichungen in Simulink 260
For-Schleife 124 Zustandsraummodelle 270
While-Schleife 131 Lösung von Regelungsaufgaben mit Simulink
Grafische Ausgabe Drehzahlregelung eines Gleichstrommotors 280
Allgemeines zum plot-Befehl 138 Aktive Schwingungstilgung 289

19. April 2022 | Sinapius | Al Natsheh


Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 3
Organisatorisches
Termine
Vorlesung: Mi., 09:45 – 11:15 PC-Saal, Langer Kamp 6
Übung: Mi., 11:30 – 13:00, 14 tägig PC-Saal, Langer Kamp 6
Labor: Termine/Ort werden rechtzeitig bekanntgegeben
Klausur: Schriftlich
Programmieraufgaben
Sprechstunde: Nach Vereinbarung
Modul: MB-IAF-10 (2510018) 5 Leistungspunkte
Skript
Wird hochgeladen, Übungsblätter im [Link]
Kontakt
Naser Al Natsheh
Raum 108
Email: [Link]@[Link]
Tel: 0531 391 2689

19. April 2022 | Sinapius | Al Natsheh


Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 4
Inhalt

 Einführung in Modellierung und Simulation von dynamischen Systemen mit


Skriptsprachen am Beispiel MATLAB/Simulink
 Grundfunktionalitäten wie Matrizen und Funktionen
 Zustandsraumdarstellung adaptronische Systeme
 Datenstrukturen und Datenfluss in der Simulation adaptronischer Systeme
 Übertragungsfunktionen / FRF
 Hierarchische Modellierung mit Hilfe grafischer Blöcke
 Einfache Regler mit SIMULINK
 Anwendungen aus dem Gebiet der Adaptronik an Hand von Laborbeispielen

19. April 2022 | Sinapius | Al Natsheh


Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 5
Einführung Was ist MATLAB?

 MATrix LABoratory, Matlab arbeitet mit Matrizen


 Interaktive Entwicklungsumgebung
 Leistungsfähiges numerisches Berechnungs- und Simulationswerkzeug für technische und
wissenschaftliche Aufgaben
 High-Level Sprache: Programmieren ist leicht und führt zu schnellen Erfolgen.
 Lösung komplexer Aufgaben ohne besondere Programmierkenntnisse
 Datenanalyse
 Integrierte Visualisierung
 Interpretersprache (keine Compilersprache wie Java, Pascal, Fortran oder C, mit der Toolbox
„Matlab Compiler“ können exe-Dateien erstellt werden)

19. April 2022 | Sinapius | Al Natsheh


Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 6
Einführung Was ist MATLAB?

 Hat eine Vielzahl an implementierten Funktionen - hohe Qualität der Numerik.


 Leistungsfähiger mathematischer Kern
 Bietet eine schnelle Realisierung von eigenen Algorithmen
 Bündelung von Funktionen in Toolboxes für bestimmte Problemklassen, wie z. B. Signal- und
Bildverarbeitung, Regelungstechnik, Statistik, symbolisches Rechnen u.v.m. (über 40 Toolboxes
erhältlich)
 Matlab besitzt Schnittstellen zu anderen Programmiersprachen.
 MATLAB-Programme sind vollständig portierbar.
 Weit verbreitetes Programm
 Kommerzielles Programm, jährliche Lizenzgebühren
 Black-Box

19. April 2022 | Sinapius | Al Natsheh


Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 7
Einführung Was ist MATLAB?

Eine Studentenversion von MATLAB kann z. B. über


[Link]
erworben werden.
Die “MATLAB and Simulink Student Suite R2022a”
kostet aktuell (14.04.2022) 69,00 € und enthält folgende Module:

 MATLAB  Optimization Toolbox


 Simulink  Parallel Computing Toolbox
 Control Systems Toolbox  Signal Processing Toolbox
 Curve Fitting Toolbox  Statistics and Machine Learning Toolbox
 DSP System Toolbox  Symbolic Math Toolbox
 Image Processing Toolbox
 Instrument Control Toolbox

19. April 2022 | Sinapius | Al Natsheh


Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 8
Einführung Literatur

 Angermann, A.; Beuschel, M.; Rau, M.; Wohlfarth, U.: Matlab – Simulink – Stateflow: Grundlagen,
Toolboxen, Beispiele, De Gruyter Studium, 2020 (E-Book)
 Quarteroni, M.; Saleri, F.: Wissenschaftliches Rechnen mit MATLAB, Springer Verlag, Heidelberg,
2006 (E-Book)
 Pietruszka, W. D.: MATLAB und Simulink in der Ingenieurpraxis, Springer, 2021 (E-Book)
 Schweizer, W.: MATLAB kompakt, DE Gruyter/Oldenburg, 2022 (E-Book)
 .
 .

19. April 2022 | Sinapius | Al Natsheh


Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 9
Lehrevaluation SS2018

19. April 2022 | Sinapius | Al Natsheh


Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 10
LehrLEO 2015

19. April 2022 | Sinapius | Al Natsheh


Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 11
Confucius (Chinese philosopher) said: Konfuzius sagte:

“Der Mensch hat dreierlei Wege klug zu handeln:


Erstens durch nachdenken, das ist der edelste,
zweitens durch nachahmen, das ist der leichteste, und
drittens durch Erfahrung, das ist der bitterste.“

“By three methods we may learn wisdom:


First, by reflection, which is noblest;
Second, by imitation, which is easiest; and
third by experience, which is the bitterest.”

19. April 2022 | Sinapius | Al Natsheh


Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 12
Grundlagen Erste Schritte

Starten und Beenden von MATLAB

Starten:

 Doppelklick auf die MATLAB-Verknüpfung


 Über die Taskleiste
 Eingabe von matlab

Beenden:

 Aus dem Kommandofenster mit quit oder exit


 Über das File-Menü
 Über das Fenstersymbol
 Mit den Tasten Strg und q

19. April 2022 | Sinapius | Al Natsheh


Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 13
Grundlagen MATLAB-Desktop(1)

Workspace
Current Directory Editor Browser
Browser Anzeige der
Textverarbeitungsprogramm aktuellen Variablen
und „Debugger“
Anzeige des aktuellen
Verzeichnisses

Show ... Actions

Command Window Command


Interaktive History
Befehlseingabe Anzeige der letzten
Kommandos
Waiting for input/Initializing/Ready/Busy/….._
19. April 2022 | Sinapius | Al Natsheh
Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 14
Grundlagen MATLAB-Desktop(2)

Hilfe

Aktuelles Verzeichnis

Laden bzw. Speichern von Daten

Öffnen einer existierenden Datei

Starten des MATLAB-Editors

19. April 2022 | Sinapius | Al Natsheh


Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 15
Grundlagen Erste Schritte

Aktivierung der Hilfefunktion :


 Mit F1
 Im Tab Home/Help
 Mit dem Kommando doc
 Mit dem Kommando help, für Hilfe im Arbeitsfenster
 Mit dem Kommando helpwin, für Hilfe im Hilfe-Browser
 Mit dem Kommando lookfor

Syntax: help functionname


helpwin functionname
doc functionname
lookfor functionname

Weitere Funktionen: (helpdesk), demo, type 

19. April 2022 | Sinapius | Al Natsheh


Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 16
Grundlagen Hilfe in MATLAB

Beispiel:
>> help exit
exit Exit from MATLAB.
exit terminates MATLAB after running finish.m, if finish.m exists.
It is the same as QUIT and takes the same termination options.
For more information, see the help for QUIT.
See also quit.
Documentation for exit
>> help demo
>> help elfun Liste der elementaren math. Funktionen
>> help ops Liste aller Operationen

>> version Zeigt die Vesionsnummer an
>> ver Liste der installierten Toolboxen auf dem PC mit den jeweiligen Versionen
>> whatsnew MATLAB Release Notes (whatsnew will be removed in a future release) >> lookfor exit

19. April 2022 | Sinapius | Al Natsheh


Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 17
Grundlagen Hilfe in MATLAB

19. April 2022 | Sinapius | Al Natsheh


Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 18
Grundlagen Erste Befehle

Arbeiten an der Kommandozeile


Matlab als Taschenrechner
>> 12+4
Ergebnis wird der allgemeinen
ans =
Variablen ans zugewiesen
16

>> 12*3
ans = ans wird überschrieben
36

>> 3*4-2*3 >> A=5; >> 8/2


ans = >> A=A + 8*2 - 4*3 ans =
6 A= 4
9
>> B=A+5*10; keine Ausgabe >> A Nachträgliche Abfrage
A=
9
19. April 2022 | Sinapius | Al Natsheh
Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 19
Grundlagen Erste Befehle

>> x=cos(pi) >> y=cosd(60) >> z=x+y


x= y= z=
-1 0.5000 -0.5000

>> sin(1)^2 + cos(1)^2 >> pi


ans = 1 ans =
3.1416

>> alpha=[Link]
alpha =
0 45 90 135 180

>> sin(alpha).^2+cos(alpha).^2
ans =
1.0000 1.0000 1.0000 1.0000 1.0000
u.s.w.

19. April 2022 | Sinapius | Al Natsheh


Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 20
Grundlagen Command Window

 MATLAB unterscheidet zwischen Groß- und Kleinschreibung


 Eingabe einer Variable oder eines Funktionsnamen liefert deren Wert im „Command Window“
(Arbeitsfenster)
 Durch die Eingabe eines Semikolons (;) am Ende einer Anweisung wird die Ausgabe im „Command
Window“ unterdrückt
 Im „Command Window“ eingegebene Anweisungen werden „Command History“ gespeichert und
können durch Doppelklick wiederholt werden
 Im „Command Window“ eingegebene Anweisungen können zusätzlich mit den Pfeiltasten ↑ und ↓
abgerufen werden
 Mit der Tab-Taste können angefangene Befehle ergänzt werden (Autovervollständigen)

19. April 2022 | Sinapius | Al Natsheh


Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 21
Grundlagen Command Window

 In MATLAB ist keine Variablen-Deklaration notwendig!


 Eine Variable wird mit der ersten Zuweisung angelegt
 Der Name einer Variablen muss mit einem Buchstaben anfangen
 Alle Variablen (Ausnahme Strings) sind mehrdimensionale Felder von Fließkommazahlen doppelter
Präzision (64 Bit)
 Dimensionierung zu keiner Zeit erforderlich, aber empfehlenswert!
 IEEE-Standard
 Variablen werden im Workspace abgelegt und bleiben dort sichtbar bis sie gelöscht werden
 Einige Variablen wie ans, eps, j, i, inf, NaN, pi, realmax, realmin, computer sind von MATLAB
reserviert
eps: Genauigkeit der Fliesskomma-Zahlen (IEEE: 2-52)

19. April 2022 | Sinapius | Al Natsheh


Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 22
Grundlagen MATLAB-Variablen

 In Matlab können an jeder Stelle des Programms Variablen eingeführt werden!


 Variablenname (max. 63 Zeichen, zusammenhängend ) muss mit einem Buchstaben beginnen!
 Nur Buchstaben, Ziffern und Unterstriche sind erlaubt
 MATLAB unterscheidet zwischen Groß- und Kleinschreibung
 Variablen in Skript-Files benutzen den globalen Workspace, d.h. bereits vorhandene Variablen
können direkt benutzt oder überschrieben werden. Sie sind gültig bis sie explizit gelöscht werden.
 Folgende „Schlüsselwörter“ dürfen nicht als Variablennummer benutzt werden:

try, break, case, else, for, end, if, function, return, switch, spmd, global, catch, otherwise, parfor,
persistent, while

>> namelengthmax >> isvarname if >> isvarname sin


ans = ans = ans =
63 logical logical
0 1
>> iskeyword
19. April 2022 | Sinapius | Al Natsheh
Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 23
Grundlagen Einfache Fehler

>> cos=3 >> cos(1) >> cos(pi)


cos = ans = Array indices must be
3 3 positive integers or
logical values. …..

>> which cos >> clear cos


cos is a variable.

>> which cos


built-in (C:\Program
Files\MATLAB\R2015a\toolbox\matlab\elfun\@double\cos)
% double method

Um dieses Problem für die imaginäre Einheit zu vermeiden, sollte für diese
grundsätzlich 1i oder 1j anstelle von i bzw. j geschrieben werden!

19. April 2022 | Sinapius | Al Natsheh


Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 24
Grundlagen MATLAB-Variablen

Beispiele:
>> i, j, pi >> 1/0 >> 0/0 >> eps
ans =
0 + 1.0000i ans = ans = ans =
ans =
0 + 1.0000i Inf NaN 2.2204e-16
ans =
3.1416
>> sin(pi)
ans =
1.2246e-16
Das Fließkommaformat

19. April 2022 | Sinapius | Al Natsheh


Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 25
Grundlagen Nützliche Befehle (1)

 Alle definierten Variablen werden mit ihren Werten im Workspace gespeichert


 who: Listet alle Variablen auf
 whos : Listet alle Variablen mit deren Eigenschaften auf
 dir, ls : Listet den Inhalt des aktuellen Verzeichnisses auf
 what übung: Listet den Inhalt des Verzeichnisses „übung“ auf
 clear x: Löscht die Variable x
 clear: Löscht alle Variablen
 clc: Löscht das Matlab-Command-Window und setzt den Cursor in die linke
obere Ecke
 home: Setzt den Cursor in die linke obere Ecke
 type datei: zeigt den Inhalt der Datei „datei.m“ an
 echo off: Unterdrückt die Ausgabe im „Command Window“ echo on: Aktiviert die
Ausgabe im „Command Window“
 format compact: Unterdrück die Leerzeilen bei der Ausgabe

19. April 2022 | Sinapius | Al Natsheh


Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 26
Grundlagen Nützliche Befehle (1)

Beispiele:
>> who >> whos
Name Size Bytes Class Attributes
Your variables are:
alpha 1x5 40 double
alpha ans x y z ans 1x1 8 double
x 1x1 8 double
>> clc y 1x1 8 double
>> clear x z 1x1 8 double
>> who
>> type help
>> type sign Befehle können nicht rückgängig
>> edit sign gemacht werden!
>> edit gradient

19. April 2022 | Sinapius | Al Natsheh


Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 27
Grundlagen Vektoren und Matrizen (1)

1) Direkte Eingabe in eckige Klammern [ ]


 Spaltentrennung: Leerzeichen oder Komma (,)
 Zeilentrennung: Semikolon (;) oder Zeilenumbruch

Beispiele:
>> a= [4 9 2] >> b=[4;9;7] >> B= [2 4 6
b= 8 10 12
a= 4 14 16 18]
9 B=
4 9 2 7 2 4 6
8 10 12
14 16 18

Ist in einer Matrix mindestens ein Element eine Dezimalzahl,


so werden alle Elemente als Dezimalzahlen dargestellt!

19. April 2022 | Sinapius | Al Natsheh


Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 28
Grundlagen Vektoren und Matrizen (1a)

>> A= [1 2 3; 4 5 6; 7 8 9]
A=
1 2 3
4 5 6
7 8 9
Die Elemente einer Matrix können auch als Ergebnis
beliebiger mathematischer Operation sein

>> C=[1/5 sqrt(9) exp(1);sqrt(5) 5*6 4-6;2 5^2 log(7)]

C=

0.2000 3.0000 2.7183


2.2361 30.0000 -2.0000
2.0000 25.0000 1.9459

19. April 2022 | Sinapius | Al Natsheh


Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 29
Grundlagen Vektoren und Matrizen (2)

Beispiele: >> c(4)=input('Bitte eine Zahl eingeben!')


>> a= [4 9 2]; Bitte eine Zahl eingeben! 0
>> c= [5 a 9]; c=
5 4 9 0 9

>> c >> c(:)=-5 >> B(:)=0


c= c= B=
5 4 9 2 9 -5 -5 -5 -5 -5 0 0 0
0 0 0
0 0 0

>> c(4)=-1 >> [m,n]=size(c) >> size(B)


c= m= ans =
5 4 9 -1 9 1
n= 3 3
5

19. April 2022 | Sinapius | Al Natsheh


Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 30
Grundlagen Vektoren und Matrizen (3)

2) Vektoren mit Zahlenfolgen: Über den Doppelpunktoperator


Syntax: x=Anfangswert:Schrittweite:Endwert
Beispiele:
>> v=[Link] >> w=10:-1:3

v= w=
1 3 5 7 9 10 9 8 7 6 5 4 3

>> u=1:6 (Schrittweite=1) >> a=-1:0.75:2

u= a=

1 2 3 4 5 6 -1.0000 -0.2500 0.5000 1.2500 2.0000

>> length(a) Gibt die Länge des Vektors a an.


>> a=[0:pi/10:pi]  ans =
5
19. April 2022 | Sinapius | Al Natsheh
Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 31
Grundlagen Vektoren und Matrizen (4)

3) Vektoren mit linspace erzeugen


Syntax: y = linspace(a,b,n) , y = linspace(a,b)

Erzeugt einen Vektor der Länge n von äquidistanten 𝑏−𝑎


∆=
Elementen zwischen den Randwerten a und b. 𝑛−1

Beispiele:

>> a=linspace(1,3,5) >> b=linspace(1,3)

a= b =.......

1.0000 1.5000 2.0000 2.5000 3.0000

y = logspace(a,b,n) wie linspace, jedoch logarithmische Skalierung 

>> y = logspace(0, 2, 10)


19. April 2022 | Sinapius | Al Natsheh
Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 32
Grundlagen Vektoren und Matrizen (5)

4) Spezial-Matrizen
Einheitsmatrix Eins-Matrix
Syntax Syntax
A = eye(n) A = ones(n)
A = eye(m,n) A = ones(m,n)
>> eye(4) >> ones(6)
ans = ans =
1 0 0 0 1 1 1 1 1 1
0 1 0 0 1 1 1 1 1 1
0 0 1 0 1 1 1 1 1 1
0 0 0 1 1 1 1 1 1 1
1 1 1 1 1 1
>> eye(2,3) 1 1 1 1 1 1
ans =
1 0 0
0 1 0

19. April 2022 | Sinapius | Al Natsheh


Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 33
Grundlagen Vektoren und Matrizen (6)

4) Spezial-Matrizen
Null-Matrix Diagonal-Matrix magisches Quadrat
Syntax Syntax Syntax
B = zeros(n) B = diag(m:n) B = magic(n), n > 2
B = zeros(m,n)

>> zeros(4,3) >> diag(4:8) >> A=magic(3)


ans = ans = A=
0 0 0 4 0 0 0 0 8 1 6
0 0 0 0 5 0 0 0 3 5 7
0 0 0 0 0 6 0 0 4 9 2
0 0 0 0 0 0 7 0 die Summen der
0 0 0 0 8 Elemente aller Zeilen,
aller Spalten und der
beiden Diagonalen sind
triu: oberes Dreieck einer Matrix gleich.
Weitere Matrizen 
tril: unteres Dreieck einer Matrix

19. April 2022 | Sinapius | Al Natsheh


Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 34
Grundlagen Vektoren und Matrizen (7)

5) Matrizen mit Zufallswerten


Zufallswerten zwischen Normalverteilte Zufallswerte
1 und 0

Syntax Syntax
B = rand(m,n) B = randn (m,n)

>> B=rand(6,4) >> D=randn(4,3)


B= D=
0.6787 0.7060 0.6948 0.7655 1.0933 -1.2141 -0.7697
0.7577 0.0318 0.3171 0.7952 1.1093 -1.1135 0.3714
0.7431 0.2769 0.9502 0.1869 -0.8637 -0.0068 -0.2256
0.3922 0.0462 0.0344 0.4898 0.0774 1.5326 1.1174
0.6555 0.0971 0.4387 0.4456
0.1712 0.8235 0.3816 0.6463

19. April 2022 | Sinapius | Al Natsheh


Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 35
Grundlagen Vektoren und Matrizen (8)

6) Block-Matrizen
Syntax Erzeugt eine Blockmatrix mit
replicate
B = repmat(A,m,n) (nxm) aus A Blöcken

>> B = repmat(eye(2),3,4) >> A = [1 3;5 7];


B= >> B = repmat(A,1,2)
11 0 1 0 1 0 1 0
00 1 0 1 0 1 0 1 B=
1 0 1 0 1 0 1 0
0 1 0 1 0 1 0 1 1 3 1 3
1 0 1 0 1 0 1 0 5 7 5 7
0 1 0 1 0 1 0 1

 blkdiag(a,b, c, d,..): Blockdiagonalmatrix.


Weitere Matrizen  diag(v,k): Matrix der Größe (n + |k|)x(n + |k|) mit den 
Einträgen des Vektors vn auf der k-ten Nebendiagonalen

19. April 2022 | Sinapius | Al Natsheh


Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 36
Grundlagen Vektoren und Matrizen (9)

7) Matrizen mit meshgrid


Syntax
[X,Y] = meshgrid(x,y)
[X,Y] = meshgrid(start:Schritt:Ende)
[X,Y] = meshgrid(startx:Schrittx:Endex, starty:Schritty:Endey)

Erzeugt aus den Vektoren x, y der Länge n und m die Matrizen X und Y mit je nxm Elementen. Jede
Zeile von X besteht aus x und jede Spalte von Y besteht aus y.

>> [X,Y]=meshgrid(1:4,-1:3)
X= Y=
1 2 3 4 -1 -1 -1 -1
1 2 3 4 Die Matrizen X und Y werden für
0 0 0 0
1 2 3 4 das Plotten von Funktionen mit zwei
1 1 1 1
1 2 3 4 Variablen und für dreidimensionale
2 2 2 2
1 2 3 4 Graphiken verwendet.
3 3 3 3
19. April 2022 | Sinapius | Al Natsheh
Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 37
Grundlagen Einfache Fehler

>> a=a+ >> b=(a+1


a=a+ b=(a+1
↑ ↑
Error: Invalid expression. Check for Error: Invalid expression. When calling a function or
missing or extra characters.. indexing a variable, use parentheses. Otherwise, check
for mismatched delimiters.

>> b=(a+1] >> 3a=sqrt(9)


b=(a+1] 3a=sqrt(9)
↑ ↑
Error: Unbalanced or unexpected Invalid expression. Check for missing multiplication
parenthesis or bracket. operator, missing or unbalanced delimiters, or other
syntax error. To
>> 4,5*5 ans = construct matrices, use brackets instead of parentheses.
4
ans =
25

19. April 2022 | Sinapius | Al Natsheh


Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 38
Grundlagen

>> A=magic(3) >> B=inv(A) >> format rat


(long, bank, short, hex, loose, +)
A= B=
8 1 6 0.1472 -0.1444 0.0639
3 5 7 -0.0611 0.0222 0.1056
4 9 2 -0.0194 0.1889 -0.1028
>> B >> D=[1:6;6:12]
B=
Dimensions of arrays being concatenated are
53/360 -13/90 23/360 not consistent.
-11/180 1/45 19/180
-7/360 17/90 -37/360 >> why >> load earth
....... >> image(X)
>> C=[1:6;6:11] >> C(2,3)
C= ans = >> logo >> colormap(map)
1 2 3 4 5 6 8 >> spy >> axis image
6 7 8 9 10 11 >> C(1,5) >> penny
ans =
5  >> type why
19. April 2022 | Sinapius | Al Natsheh
Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 39
Vektoren und Matrizen Transposition/Kombination

>> a= [1 2 3]; >> b=[4;5;6]; >> E=[F b]


E=
Transposition: Kombination: 4 1 4
>> c=a' >> e=[a b'] 5 2 5
c= e= 6 3 6
1 1 2 3 4 5 6
2 >> G=[E,[5;6;7]]
3 >> c=[-2*b' a] G=
c= 4 1 4 5
-8 -10 -12 1 2 3 5 2 5 6
>> d=b' 6 3 6 7
d=
>> F=[b a'] >> K=[E;[5 6 7]]
4 5 6
F= K=
4 1 4 1 4
5 2 5 2 5
6 3 6 3 6
5 6 7
19. April 2022 | Sinapius | Al Natsheh
Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 40
Vektoren und Matrizen Konjugierte Transposition

>> I=eye(3)+i*ones(3)
I=
1.0000 + 1.0000i 0 + 1.0000i 0 + 1.0000i
0 + 1.0000i 1.0000 + 1.0000i 0 + 1.0000i
0 + 1.0000i 0 + 1.0000i 1.0000 + 1.0000i
>> I’
ans =
1.0000 - 1.0000i 0 - 1.0000i 0 - 1.0000i Konjugierte
0 - 1.0000i 1.0000 - 1.0000i 0 - 1.0000i Transposition
0 - 1.0000i 0 - 1.0000i 1.0000 - 1.0000i
>> I.’
ans =
1.0000 + 1.0000i 0 + 1.0000i 0 + 1.0000i Transposition
0 + 1.0000i 1.0000 + 1.0000i 0 + 1.0000i
0 + 1.0000i 0 + 1.0000i 1.0000 + 1.0000i
>> I'*I >> I.'*I 
19. April 2022 | Sinapius | Al Natsheh
Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 41
Vektoren und Matrizen Indizierung/Zugriff auf Element

>> a= [1 2 3]; >> b=[4;5;6];


Zugreifen auf (Einzel)Elemente: Zugreifen auf Zeilen/Spalten:
(Der Doppelpunkt-Operator,(alle))
>> a(1,3) >> b(1:3) >> G(3,:)
ans = ans = ans =
3 4 6 3 6 7
>> a(3) 5 >> K(2:end,2:end)
ans = 6 ans =
3 2 5
>> a(end) >> E(2,2) 3 6
ans = ans = 6 7
3 2
>> a(1:3) >> K(3:end,2:end)
ans =
1 2 3  Index: Position im Vektor
 Achtung: Indizes beginnen in Matlab immer mit 1!

19. April 2022 | Sinapius | Al Natsheh


Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 42
Vektoren und Matrizen Bildung von Untermatrizen

>> G=[4 1 4 5;5 2 5 6;6 3 6 7] >> S=[1 2 3;4 5 6;7 8 9]


G= S=
4 1 4 5 1 2 3
5 2 5 6 4 5 6
6 3 6 7 7 8 9

>> G([1 2], [2 3]) >> G(end,end-1)


ans = ans =
1 4 6
2 5
Streichung einer Zeile/Spalte
>> G(1:3, [3 4]) >> G(2,:)=[ ] >> G(:,3)=[ ]
ans = G= G=
4 5 4 1 4 5 4 1 5
5 6 6 3 6 7 5 2 6
6 7 6 3 7

19. April 2022 | Sinapius | Al Natsheh


Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 43
Vektoren und Matrizen Bildung von Untermatrizen

Änderung von Elementen


>> G(2,3) = -7 >> G(:,1)=0 >> G(:,3)=[1; 5; -7]
G= G= G=
4 1 4 5 0 1 4 5 4 1 1 5
5 2 -7 6 0 2 5 6 5 2 5 6
6 3 6 7 0 3 6 7 6 3 -7 7

S neben G 3. Spalte von G neben S

>> M=[S,G] >> N=[S,G(:,3)]


M= N=
1 2 3 4 1 4 5 1 2 3 4
4 5 6 5 2 5 6 4 5 6 5 u.s.w.
7 8 9 6 3 6 7 7 8 9 6

19. April 2022 | Sinapius | Al Natsheh


Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 44
Vektoren und Matrizen Addition/Subtraktion
Matrix-Dimensionen müssen übereinstimmen!
>> A=[1 2 3;4 5 6;7 8 9] >> B=A' >> x=[1;1;1] >> y=[2 3 4]
A= B= x= y=
1 2 3 1 4 7 1 2 3 4
4 5 6 2 5 8 1
7 8 9 3 6 9 1
>> A+B >> A-B >> A+x >> A+y
ans = ans = ans = ans =
2 6 10 0 -2 -4 2 3 4 3 5 7
6 10 14 2 0 -2 5 6 7 6 8 10
10 14 18 4 2 0 8 9 10 9 11 13
>> A+1 >> x+1
ans = ans =
(komponentenweise Addition einer
2 3 4 2
Zahl zu Vektoren und Matrizen)
5 6 7 2
8 9 10 2
19. April 2022 | Sinapius | Al Natsheh
Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 45
Vektoren und Matrizen Multiplikation
Anzahl der Spalten der ersten Matrix = Anzahl der Zeilen der zweiten Matrix
>> A=[1 2 3;4 5 6;7 8 9]; >> B=A'; >> x=[1;1;1];

>> A*B >> B*A >> 2*A


ans = ans = ans =
14 32 50 66 78 90 2 4 6
32 77 122 78 93 108 8 10 12
50 122 194 90 108 126 14 16 18

>> A*x >> x*A


ans = Error using *
6 Incorrect dimensions for matrix multiplication. Check that the
15 number of columns in the first matrix matches the number of
24 rows in the second matrix. To perform elementwise
multiplication, use '.*'.
19. April 2022 | Sinapius | Al Natsheh
Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 46
Vektoren und Matrizen Beispiel
Berechnen Sie den Schwerpunkt des skizziertem Massenpunktsystems.

y
>> M=[5 2 4 3 6 1];
>> XYZ=[3 4 0
460
650
2kg 6kg 720
4kg 960
5kg 10 3 0];
1kg >> rs=M*XYZ/sum(M)
3kg rs =
6.2857 4.6190 0
x
σ 𝑟റ𝑖 𝑚𝑖
𝑟റ𝑠 =
σ 𝑚𝑖

19. April 2022 | Sinapius | Al Natsheh


Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 47
Vektoren und Matrizen Skalarprodukt

>> a= [1 -2 3]; >> b=[4;5;6];

Skalarprodukt: 𝑎റ ∙ 𝑏 = 𝑎റ 𝑏 cos 𝜑

>> dot(a,b) >> dot(b,a) >> a*b >> sum(a.*b')


ans = ans = ans = ans =
12 12 12 12

Norm eines Vektors: 𝑎 = 𝑎12 + 𝑎22 + ⋯ + 𝑎𝑛2 Vorsicht!

>> b*a
>> norm(a) >> abs(a) ans =
ans = ans = 4 -8 12
3.7417 1 2 3 5 -10 15
6 -12 18
19. April 2022 | Sinapius | Al Natsheh
Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 48
Vektoren und Matrizen Skalarprodukt

>> a= [1 -2 3]; >> b=[4;5;6];


𝑎റ ∙ 𝑏
>> phi=acosd(dot(a,b)/(norm(a)*norm(b))) 𝜑 = 𝑐𝑜𝑠 −1
𝑎റ 𝑏
phi =
68.5624
>> phi=acosd(dot(a,b)/norm(a)/norm(b))

Weitere Operationen:
>> a.*a >> a*a' >> a.^2
ans = ans = ans =
1 4 9 14 1 4 9
>> a*a
Error using *
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix
matches the number of rows in ……. .

19. April 2022 | Sinapius | Al Natsheh


Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 49
Vektoren und Matrizen Kreuzprodukt

>> sqrt(abs(a)) >> a^2


ans = ??? Error using ==> mpower
1.0000 1.4142 1.7321 Inputs must be a scalar and a square matrix.

>> exp(abs(a)) >> log(ans)


ans = ans =
2.7183 7.3891 20.0855 1 2 3

Kreuzprodukt: 𝑎റ × 𝑏 = 𝑎റ 𝑏 sin 𝜑
>> cross(a,b) >> cross(b,a)
ans = ans =
-27 6 13 27 -6 -13

𝑎റ × 𝑏
>> phi=asind(norm(cross(a,b))/(norm(a)*norm(b))) 𝜑 = sin−1
phi = 𝑎റ 𝑏
68.5624

19. April 2022 | Sinapius | Al Natsheh


Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 50
Arrayverknüpfung

Komponentenweise Verknüpfung miteinander korrespondierender Arrayelemente zweier Arrays. Dazu


wird ein Punkt vor den Operator gesetzt. (.*, ./, und .^)

Beispiele  Die zu verknüpfenden Arrays müssen vom gleichen Typ sein!


>> A=[1 2;3 4];  Addition und Subtraktion werden komponentenweise ausgeführt (kein Punkt!)
>> B=[5 6;7 8];
>> A*B
ans =
19 22 1 2 5 6 1∙5+2∙7 1∙6+2∙8 19 22
∗ = =
43 50 3 4 7 8 3∙5+4∙7 3∙6+4∙8 43 50

>> A.*B
ans =
5 12 1 2 5 6 1∙5 2∙6 5 12
∙∗ = =
21 32 3 4 7 8 3∙7 4∙8 21 32

19. April 2022 | Sinapius | Al Natsheh


Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 51
Arrayverknüpfung Beispiele

>> A=[1 2;3 4]; >> B=[5 6;7 8];


>> A^2 >> A.^2 >> 3.*A >> 3*A

ans = ans = ans = ans =


7 10 1 4 3 6 3 6
15 22 9 16 9 12 9 12

>> A*A >> A.*A >> A./B >> A./A

ans = ans = ans = ans =


7 10 1 4 0.2000 0.3333 1 1
15 22 9 16 0.4286 0.5000 1 1

>> 3/A >> 3./A


Error using / ans =
Matrix dimensions must agree. 3.0000 1.5000
1.0000 0.7500
19. April 2022 | Sinapius | Al Natsheh
Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 52
Arrayverknüpfung Beispiele

Berechnen Sie die Ersatzfedersteifigkeit


>> F=50;
cers und die Auslenkungen xi der einzelnen
>> c= [10 14 24];
Federn des skizzierten Systems. >> cers=1/sum(1./c)
cers =
4.6927
>> x=F/cers
x=
𝑮𝒆𝒈𝒆𝒃𝒆𝒏: 10.6548
𝑁 𝑁 𝑁 >> xi=F./c
𝑐1 = 10 , 𝑐 = 14 , 𝑐3 = 24 , 𝐹 = 50𝑁.
𝑚𝑚 2 𝑚𝑚 𝑚𝑚 xi =
5.0000 3.5714 2.0833
Lösung:
>> sum(xi)-x
1 𝐹
𝑐𝑒𝑟𝑠 = 𝑥𝑖 = ans =
1 1 1 𝑐𝑖 0
+ +
𝑐1 𝑐2 𝑐3

19. April 2022 | Sinapius | Al Natsheh


Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 53
Vektoren und Matrizen Weitere Funktionen (1)

>> length(A) >> size(A) >> min(A)


A=
ans = ans = ans =
2 8 9
4 4 3 0 1 1
4 1 3
7 6 1
>> sum(A) >> prod(A) >> max(A)
0 5 4
ans = ans = ans =
13 20 17 0 240 108 7 8 9

Kumulative Summe

>> sort(A) >> cumsum(A) >> cumprod(A) >> diff(A)


ans = ans = ans = ans =
0 1 1 2 8 9 2 8 9 2 -7 -6
2 5 3 6 9 12 8 8 27 3 5 -2
4 6 4 13 15 13 56 48 27 -7 -1 3
7 8 9 13 20 17 0 240 108
 sort(A,2), sort(A,1), sum(A,2)
19. April 2022 | Sinapius | Al Natsheh
Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 54
Vektoren und Matrizen Weitere Funktionen (2)
A= B=
2 8 9 1 4 0 9
4 1 3 2 5 9 10
7 6 1 3 2 12 8
0 5 4
>> min(A,B') >> max(A,B') >> min(A,2) >> max(A,3)
ans = ans = ans = ans =
1 2 3 2 8 9 2 2 2 3 8 9
4 1 2 4 5 3 2 1 2 4 3 3
0 6 1 7 9 12 2 2 1 7 6 3
0 5 4 9 10 8 0 2 2 3 5 4
>> min(A,[ ],1) >> min(A,[ ],2) >> max(A,[ ],1) >> max(A,[ ],2)
ans = ans = ans = ans =
0 1 1 2 7 8 9 9
1 4
1 7
0 5
19. April 2022 | Sinapius | Al Natsheh
Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 55
Vektoren und Matrizen Weitere Funktionen (3)

Maxima bzw. Minima einer Matrix und deren Position.


A=
1.00 2.00 3.00
Beispiel: >> A=[1 2 3;4 5 6;7 8 9]
4.00 5.00 6.00
7.00 8.00 9.00

>> [a b]=max(A) >> [a b]=max(A,[ ],2) >> [a b]=min(A,[ ],1)


a= a= a=
7 8 9 3 1 2 3
b= 6 b=
3 3 3 9 1 1 1
>> [a b]=max(A,[ ],1) b=
a= 3
7 8 9 3
b= 3
3 3 3
19. April 2022 | Sinapius | Al Natsheh
Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 56
Datenanalyse Zusammenfassung

Funktion Beschreibung
max(x) Maximun
min(x) Minimum
sum(x) Summe
diff(x) Differenz
prod(x) Produkt
mean(x) Arithmetischer Mittelwert
Median(x) Median
std(x) Standardabweichung
sort(x) Sortiert
cumsum(x) Kumulative Summe
cumprod(x) Kumulatives Produkt
19. April 2022 | Sinapius | Al Natsheh
Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 57
Vektoren und Matrizen Weitere Funktionen (4)

B=
1 4 0 9
Umordnen von Matrizen
2 5 9 10
3 2 12 8

>> reshape(B,2,6) >> reshape(B,6,[ ])


ans = ans =
1 3 5 0 12 10 1 0
2 4 2 9 9 8 2 9
3 12
4 9
5 10
2 8

Weitere vordefinierte Matrizen:  >> help gallery 

19. April 2022 | Sinapius | Al Natsheh


Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 58
Vektoren und Matrizen Weitere Funktionen (5)

>> A=[1 2 3;4 5 6]


A= Kippen (Spiegeln)/Rotieren
1 2 3 von Matrizen
4 5 6

>> fliplr(A) >> flipud(A) >> rot90(A)


ans = ans = ans =
3 2 1 4 5 6 3 6
6 5 4 1 2 3 2 5
1 4
Funktionen von Matrizen
>> S=[0 30 45;60 90 120;135 180 225] >> sind(S)
S= ans =
0 30 45 0 0.5000 0.7071
60 90 120 0.8660 1.0000 0.8660
135 180 225 0.7071 0 -0.7071 u.s.w.

19. April 2022 | Sinapius | Al Natsheh


Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 59
Beispiele

>>F=[(1:12)' ,cumprod(1:12)'] >> m=10,n=8,A=1:m*n;B=reshape(A,m,n)'


F= B=
1 1 1 2 3 4 5 6 7 8 9 10
2 2 11 12 13 14 15 16 17 18 19 20
3 6 21 22 23 24 25 26 27 28 29 30
4 24 31 32 33 34 35 36 37 38 39 40
5 120 41 42 43 44 45 46 47 48 49 50
6 720 51 52 53 54 55 56 57 58 59 60
7 5040 61 62 63 64 65 66 67 68 69 70
8 40320 71 72 73 74 75 76 77 78 79 80
9 362880
Fakultät

>> phi =pi/6;


10 3628800
11 39916800 >> A=[cos(phi) sin(phi);-sin(phi) cos(phi)]
12 479001600 >> A(1,1) = cos(phi); A(1,2) = sin(phi);
>> factorial(12) A(2,1) = -sin(phi); A(2,2) = cos(phi);
ans = A=
479001600 0.8660 0.5000
-0.5000 0.8660 Drehmatrix
19. April 2022 | Sinapius | Al Natsheh
Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 60
Beispiele

>> C=diag(1:12); >> C(1,:)=1:12 >> C(:,1)=1:12

C=

1 2 3 4 5 6 7 8 9 10 11 12
2 2 0 0 0 0 0 0 0 0 0 0
3 0 3 0 0 0 0 0 0 0 0 0
4 0 0 4 0 0 0 0 0 0 0 0
5 0 0 0 5 0 0 0 0 0 0 0
6 0 0 0 0 6 0 0 0 0 0 0
7 0 0 0 0 0 7 0 0 0 0 0
8 0 0 0 0 0 0 8 0 0 0 0
9 0 0 0 0 0 0 0 9 0 0 0
10 0 0 0 0 0 0 0 0 10 0 0
11 0 0 0 0 0 0 0 0 0 11 0
12 0 0 0 0 0 0 0 0 0 0 12

19. April 2022 | Sinapius | Al Natsheh


Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 61
Lineare Algebra

>> A=[3 2 1;1 0 2;4 1 3] Rang einer Matrix


A= >> rank(A)
3 2 1 ans =
1 0 2 3
4 1 3
Inverse Matrix: 𝑨𝑨−1 = 𝑬 Eigenwerte Spur einer Matrix
>> B=inv(A), auch (B=A^-1) >> eig(A) >> trace(A);
B= ans = >> sum(diag(A))
-0.4000 -1.0000 0.8000 5.9727 ans =
1.0000 1.0000 -1.0000 0.0136 + 0.9149i 6
0.2000 1.0000 -0.4000 0.0136 - 0.9149i
Determinante:
>> det(A)  pinv: Pseudoinverse, poly:charakteristisches Polynom

ans =  rref: Gauss-Algorithmus
5
19. April 2022 | Sinapius | Al Natsheh
Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 62
Lineare Gleichungssysteme bestimmte Systeme

>> A=[3 2 1;1 0 2;4 1 3]; >> rank(A) >> x=A\b


>> b=[2;3;1]; ans = x=
3 -3
>> x=inv(A)*b A: quadratisch,
regulär! 4
x=
3
-3
4
3 >> rref([A,b])

19. April 2022 | Sinapius | Al Natsheh


Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 63
Lineare Gleichungssysteme bestimmte Systeme

X = A\B  X = A-1*B = Lösung der Gleichung A*X = B


X = A/B  X = A*B-1 = Lösung der Gleichung X*B = A

x = A\b hat gegenüber x = inv(A)*b folgende Vorteile:

 A\b verwendet aus numerischer Sicht bessere Verfahren. Dies betrifft zum einen die
Geschwindigkeit, vor allem aber die Genauigkeit der Lösung.

 x = A\b liefert auch dann eine Lösung, wenn das Gleichungssystem nicht eindeutig lösbar ist. Im
Fall eines überbestimmten Systems wird eine Lösung angegeben, bei der der quadratische Fehler
von Ax−b minimal ist.

19. April 2022 | Sinapius | Al Natsheh


Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 64
Lineare Gleichungssysteme überbestimmte Systeme

Messung der Abstände von vier Punkten auf einer Geraden.

I II III IV

x1 x2 x3

𝑥1 = 1,1
𝑥2 = 1,9
𝑥3 = 3,2
𝑥1 + 𝑥2 = 3,1
𝑥1 + 𝑥2 + 𝑥3 = 6,0
𝑥2 + 𝑥3 = 4,9

19. April 2022 | Sinapius | Al Natsheh


Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 65
Lineare Gleichungssysteme überbestimmte Systeme

1 0 0 1,1 >> A=[1 0 0


0 1 0 1,9 010
𝑥1 001
0 0 1 𝑥2 = 3,2
1 1 0 3,1 110
𝑥3 111
1 1 1 𝑥
6,0
0 1 1 4,9 0 1 1];
𝐴 𝑏 >> b=[1.1;1.9;3.2;3.1;6.0;4.9];
>> x=A\b
x=
Diese Lösung stellt die im Sinne minimaler 1.1250
Fehlerquadrate am besten zu allen sechs 1.8750
Messungen passenden Abstände zwischen den 3.0750
Punkten dar.
>> rank(A)
ans =
3
19. April 2022 | Sinapius | Al Natsheh
Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 66
Lineare Gleichungssysteme unterbestimmte Systeme

3 2 1 𝑥1 2 >> A=[3 2 1;1 0 2;4 2 3], >> b=[2 3 5]'


1 0 2 𝑥2 = 3
4 2 3 𝑥3 ถ5 >> rank(A)
𝐴 𝑥 𝑏
ans =
>> x=A\b, >> inv(A)*b 2
Warning: Matrix is singular to working
>> b1=A*x
precision.
b1 =
x=
1.999999999999998
Inf
2.999999999999999
Inf
4.999999999999997
Inf
>> x=pinv(A)*b >> rref([A,b])
x= ans =
0.377777777777777 1.0000 0 2.0000 3.0000
-0.222222222222222 0 1.0000 -2.5000 -3.5000
1.3111111111111110 0 0 0 0
19. April 2022 | Sinapius | Al Natsheh
Simulation adaptronischer Systeme mit MATLAB/SIMULINK | Seite 67

Das könnte Ihnen auch gefallen