MATLAB Repetitorium - Graphische Darstellung: Unterschied zwischen den Versionen

Aus HSHL Mechatronik
Zur Navigation springen Zur Suche springen
Keine Bearbeitungszusammenfassung
 
(26 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 5: Zeile 5:
|-
|-
| '''Termin:''' || 26.04.2024
| '''Termin:''' || 26.04.2024
|}
== Aufgabe 3.1 - Plotten von diskreten Werten ==
# Erzeugen Sie nunächst ein eindimensionales Feld x von 51 aufsteigenden Zahlen zwischen 0 und 5.
# Plotten Sie <code>sin(x)</code> über <code>x</code>.
# Plotten Sie in einer Figur die Funktionen <math>x\cdot sin(x)</math> und <math>x\cdot log(x)</math> über <code>x</code>.
# Plotten Sie nun die Kurve <code>cos(x)</code> über <code>sin(x)</code> für <math>Winkel \in [0..2\pi]</math> in einem neuen Fenster.
# Erzeugen Sie ein zweites Feld y=x und plotten Sie über dem von x und y aufgespannten zweidimensionelen Feld die Funktion <math>z=x\cdot sin(x)</math>.
## Beschriften Sie jeweils die Zeichnungen mit Überschrift und Achsenbeschriftung.
## Ordnen Sie die vier plots aus den Aufgaben 1-4 in einem 2x2 Feld an.
## Probieren Sie für (2) verchiedene Arten von Kurvenplots aus (unterschiedliche Farben, durchgezogene, gestrichelte Linien).
## Probieren Sie für (5) verschiedene Arten von Oberflächengestaltung (<code>surf, surfc, plot3</code>).
## Lassen Sie sich in jedem Plot ein Raster anzeigen (<code>grid on</code>).
## Für (5): Stellen sie ein, dass der Plot vom Benutzer rotiert werden kann per Maus (<code>rotate3d on</code>).
'''Nützliche Befehle:''' [https://de.mathworks.com/help/matlab/ref/xlabel.html <code>xlabel</code>], [https://de.mathworks.com/help/matlab/ref/subplot.html <code>subplot</code>], [https://de.mathworks.com/help/matlab/ref/title.html <code>title</code>], [https://de.mathworks.com/help/matlab/ref/title.html <code>hold on</code>], [https://de.mathworks.com/help/matlab/ref/plot.html <code>plot>/code>], [https://de.mathworks.com/help/matlab/ref/figure.html <code>figure</code>], [https://de.mathworks.com/help/matlab/ref/grid.html <code>grid on</code>], [https://de.mathworks.com/help/matlab/ref/mesh.html <code>mesh</code>], [https://de.mathworks.com/help/matlab/ref/meshgrid.html <code>meshgrid</code>], [https://de.mathworks.com/help/matlab/ref/surf.html <code>surf</code>], [https://de.mathworks.com/help/matlab/ref/surfc.html <code>surfc</code>], [https://de.mathworks.com/help/matlab/ref/plot3.html <code>plot3</code>], [https://de.mathworks.com/help/matlab/ref/axis.html <code>axis equal</code>], [https://de.mathworks.com/help/matlab/ref/surfc.html <code>zlabel</code>], [https://de.mathworks.com/help/matlab/ref/rotate3d.html <code>rotate3d on</code>]</code>
{| role="presentation" class="wikitable mw-collapsible mw-collapsed"
| <strong>Musterlösung 1&thinsp;</strong>
|-
| <source line lang="matlab" style="font-size:medium">x = (0:0.1:5);
</source>
|}
{| role="presentation" class="wikitable mw-collapsible mw-collapsed"
| <strong>Musterlösung 2&thinsp;</strong>
|-
| <source line lang="matlab" style="font-size:medium">y = sin(x);
subplot(2,2,1)
plot(x,y,'--')
title('sin(x)')
xlabel('x')
ylabel('y')
grid on;
</source>
|}
{| role="presentation" class="wikitable mw-collapsible mw-collapsed"
| <strong>Musterlösung 3&thinsp;</strong>
|-
| <source line lang="matlab" style="font-size:medium">y1 = x.*sin(x);
y2 = x.*log(x);
subplot(2,2,2)
plot(x, y1, 'r.');
hold on;
plot(x, y2, 'b-');
title('x*sin(x) | x*log(x)')
xlabel('x')
ylabel('y')
grid on;
</source>
|}
{| role="presentation" class="wikitable mw-collapsible mw-collapsed"
| <strong>Musterlösung 4&thinsp;</strong>
|-
| <source line lang="matlab" style="font-size:medium">t = (0:pi/100:2*pi);
x = sin(t);
y = cos(t);
subplot(2,2,3)
plot(x,y,'g.-');
title('cos(x) ueber sin(x)')
xlabel('x')
ylabel('y')
grid on;
</source>
|}
{| role="presentation" class="wikitable mw-collapsible mw-collapsed"
| <strong>Musterlösung 5&thinsp;</strong>
|-
| <source line lang="matlab" style="font-size:medium">[X,Y] = meshgrid(0:0.1:5,0:0.1:5);
Z = X.*sin(Y);
subplot(2,2,4)
%surf(X,Y,Z);
%surfc(X,Y,Z);
%plot3(X,Y,Z);
mesh(X,Y,Z);
%axis equal
title('x*sin(y)')
xlabel('x')
ylabel('y')
zlabel('z')
grid on;
rotate3d on;
</source>
|}
|}


== Aufgabe 3.2 - Plotten von symbolischen Funktionen ==
# Recherchieren Sie, welche Befehle es in MATLAB<sup>®</sup> zur Darstellung von Funktionsgraphen gibt.
# Zeichnen Sie folgenden symbolischen Funktionsgraphen <br> <math>y = \frac{x^2-4}{x^2+1}</math><br><math>y = \frac{x^3-5x^2+8x-4}{x^3-6x^2+12x-8}</math><br><math>y = 2\cdot \sin(3x-\frac{\pi}{6})</math>
# Recherchieren Sie, welche Befehle es in MATLAB zur Darstellung von Funktionsgraphen von Funktionen zweier Veränderlicher gibt.
# Zeichnen Sie folgenden symbolischen Funktionsgraphen <br> <math>f(x;y) = \frac{x^2-y^2}{x^2+y^2}</math><br><math>f(x;y) = -4x^3y^2+3xy^4-3x+2y+5</math>
'''Nützliche Befehle:''' figure, subplot syms, [https://www.mathworks.com/help/matlab/ref/fplot.html fplot], [https://www.mathworks.com/help/matlab/ref/xlabel.html xlabel]
{| role="presentation" class="wikitable mw-collapsible mw-collapsed"
| <strong>Musterlösung 3.2.2&thinsp;</strong>
|-
| <source line lang="matlab" style="font-size:medium">%% Aufgabe 3.2 - Plotten von symbolischen Funktionen
close all
syms x y1 y2 y3
y1 = (x.^2 - 4)./(x.^2 +1);
y2 = (x.^3 - 5.*x.^2 + 8.*x - 4)./(x.^3 - 6.*x.^2 + 12.*x -8);
y3 = 2.*sin(3.*x - (pi/6));
figure(1);
subplot(1,3,1);
fplot(y1);
xlabel('$y = \frac{x^2-4}{x^2+1}$','Interpreter','latex')
subplot(1,3,2);
fplot(y2);
xlabel('$y = \frac{x^3-5x^2+8x-4}{x^3-6x^2+12x-8}$','Interpreter','latex')
subplot(1,3,3);
fplot(y3);
xlabel('$y = 2\cdot \sin(3x-\frac{\pi}{6})$','Interpreter','latex')
</source>
|}
{| role="presentation" class="wikitable mw-collapsible mw-collapsed"
| <strong>Musterlösung 3.2.4&thinsp;</strong>
|-
| <source line lang="matlab" style="font-size:medium">syms x y z1 z2
z1 = (x.^2 - y.^2)./(x.^2 + y.^2);
z2 = -4.*x.^3.*y.^2 + 3.*x.*y.^4 - 3.*x + 2.*y + 5;
figure(2)
subplot(1,2,1);
%fsurf(z1);
%fmesh(z1);
%fimplicit3(z1);
fcontour(z1);
subplot(1,2,2);
fsurf(z2);
%fmesh(z2);
%fimplicit3(z2);
%fcontour(z2);
</source>
|}


----
----
→ Termine [[MATLAB_Repetitorium_-_Einführung|1]] <br> [[MATLAB_Repetitorium_-_Graphische_Darstellung|2]]
→ Termine [[MATLAB_Repetitorium_-_Einführung|1]] [[MATLAB_Repetitorium_-_Graphische_Darstellung|2]]<br>
→ [[MATLAB-Befehle| MATLAB<sup>®</sup> Befehlsübersicht]]<br>
→ [[MATLAB-Befehle| MATLAB<sup>®</sup> Befehlsübersicht]]<br>
→ zurück zum Hauptartikel: [[MATLAB_Repetitorium|MATLAB Repetitorium]]
→ zurück zum Hauptartikel: [[MATLAB_Repetitorium|MATLAB Repetitorium]]

Aktuelle Version vom 10. Mai 2024, 09:37 Uhr

Autor: Prof. Dr.-Ing. Schneider
Termin: 26.04.2024

Aufgabe 3.1 - Plotten von diskreten Werten

  1. Erzeugen Sie nunächst ein eindimensionales Feld x von 51 aufsteigenden Zahlen zwischen 0 und 5.
  2. Plotten Sie sin(x) über x.
  3. Plotten Sie in einer Figur die Funktionen und über x.
  4. Plotten Sie nun die Kurve cos(x) über sin(x) für in einem neuen Fenster.
  5. Erzeugen Sie ein zweites Feld y=x und plotten Sie über dem von x und y aufgespannten zweidimensionelen Feld die Funktion .
    1. Beschriften Sie jeweils die Zeichnungen mit Überschrift und Achsenbeschriftung.
    2. Ordnen Sie die vier plots aus den Aufgaben 1-4 in einem 2x2 Feld an.
    3. Probieren Sie für (2) verchiedene Arten von Kurvenplots aus (unterschiedliche Farben, durchgezogene, gestrichelte Linien).
    4. Probieren Sie für (5) verschiedene Arten von Oberflächengestaltung (surf, surfc, plot3).
    5. Lassen Sie sich in jedem Plot ein Raster anzeigen (grid on).
    6. Für (5): Stellen sie ein, dass der Plot vom Benutzer rotiert werden kann per Maus (rotate3d on).

Nützliche Befehle: xlabel, subplot, title, hold on, plot>/code>, figure, grid on, mesh, meshgrid, surf, surfc, plot3, axis equal, zlabel, rotate3d on

Aufgabe 3.2 - Plotten von symbolischen Funktionen

  1. Recherchieren Sie, welche Befehle es in MATLAB® zur Darstellung von Funktionsgraphen gibt.
  2. Zeichnen Sie folgenden symbolischen Funktionsgraphen


  3. Recherchieren Sie, welche Befehle es in MATLAB zur Darstellung von Funktionsgraphen von Funktionen zweier Veränderlicher gibt.
  4. Zeichnen Sie folgenden symbolischen Funktionsgraphen

Nützliche Befehle: figure, subplot syms, fplot, xlabel


→ Termine 1 2
MATLAB® Befehlsübersicht
→ zurück zum Hauptartikel: MATLAB Repetitorium