Modellierung und Simulation - Graphische Darstellung: Unterschied zwischen den Versionen

Aus HSHL Mechatronik
Zur Navigation springen Zur Suche springen
Keine Bearbeitungszusammenfassung
 
(2 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 3: Zeile 3:
| '''Autor:'''  || [[Benutzer:Ulrich_Schneider| Prof. Dr.-Ing. Schneider]]
| '''Autor:'''  || [[Benutzer:Ulrich_Schneider| Prof. Dr.-Ing. Schneider]]
|}
|}
= Aufgabe 3.1 - Plotten von symbolischen Funktionen =
= Aufgabe 2 - Plotten von diskreten Werten =
# Recherchieren Sie, welche Befehle es in MATLAB<sup>®</sup> zur Darstellung von Funktionsgraphen gibt.
# Erzeugen Sie zunächst ein eindimensionales Feld x von 51 aufsteigenden Zahlen zwischen 0 und 5.
# 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>
# Plotten Sie <code>sin(x)</code> über <code>x</code>.
# Recherchieren Sie, welche Befehle es in MATLAB zur Darstellung von Funktionsgraphen von Funktionen zweier Veränderlicher gibt.
# Plotten Sie in einer Figur die Funktionen <math>x\cdot sin(x)</math> und <math>x\cdot log(x)</math> über <code>x</code>.
# 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>
# 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.
'''Nützliche Befehle:''' [https://de.mathworks.com/help/matlab/ref/figure.html <code>figure</code>], [https://de.mathworks.com/help/matlab/ref/subplot.html <code>subplot</code>], [https://de.mathworks.com/help/symbolic/sym.syms.html <code>syms</code>], [https://www.mathworks.com/help/matlab/ref/fplot.html <code>fplot</code>], [https://www.mathworks.com/help/matlab/ref/xlabel.html <code>xlabel</code>]
# 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>]
{| role="presentation" class="wikitable mw-collapsible mw-collapsed"
{| role="presentation" class="wikitable mw-collapsible mw-collapsed"
| <strong>Musterlösung 2.2.2&thinsp;</strong>
| <strong>Musterlösung 1&thinsp;</strong>
|-
|-
| <source line lang="matlab" style="font-size:medium">
| <source line lang="matlab" style="font-size:medium">x = (0:0.1:5);
 
</source>
close all
|}
syms x y1 y2 y3
{| role="presentation" class="wikitable mw-collapsible mw-collapsed"
y1 = (x.^2 - 4)./(x.^2 +1);
| <strong>Musterlösung 2&thinsp;</strong>
y2 = (x.^3 - 5.*x.^2 + 8.*x - 4)./(x.^3 - 6.*x.^2 + 12.*x -8);
|-
y3 = 2.*sin(3.*x - (pi/6));
| <source line lang="matlab" style="font-size:medium">y = sin(x);
 
subplot(2,2,1)
figure(1);
plot(x,y,'--')
subplot(1,3,1);
title('sin(x)')
fplot(y1);
xlabel('x')
xlabel('$y = \frac{x^2-4}{x^2+1}$','Interpreter','latex')
ylabel('y')
 
grid on;
subplot(1,3,2);
</source>
fplot(y2);
|}
xlabel('$y = \frac{x^3-5x^2+8x-4}{x^3-6x^2+12x-8}$','Interpreter','latex')
{| role="presentation" class="wikitable mw-collapsible mw-collapsed"
 
| <strong>Musterlösung 3&thinsp;</strong>
subplot(1,3,3);
|-
fplot(y3);
| <source line lang="matlab" style="font-size:medium">y1 = x.*sin(x);
xlabel('$y = 2\cdot \sin(3x-\frac{\pi}{6})$','Interpreter','latex')
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>
</source>
|}
|}
{| role="presentation" class="wikitable mw-collapsible mw-collapsed"
{| role="presentation" class="wikitable mw-collapsible mw-collapsed"
| <strong>Musterlösung 2.2.4&thinsp;</strong>
| <strong>Musterlösung 5&thinsp;</strong>
|-
|-
| <source line lang="matlab" style="font-size:medium">syms x y z1 z2
| <source line lang="matlab" style="font-size:medium">[X,Y] = meshgrid(0:0.1:5,0:0.1:5);
z1 = (x.^2 - y.^2)./(x.^2 + y.^2);
Z = X.*sin(Y);
z2 = -4.*x.^3.*y.^2 + 3.*x.*y.^4 - 3.*x + 2.*y + 5;
subplot(2,2,4)
 
%surf(X,Y,Z);
figure(2)
%surfc(X,Y,Z);
subplot(1,2,1);
%plot3(X,Y,Z);
%fsurf(z1);
mesh(X,Y,Z);
%fmesh(z1);
%axis equal
%fimplicit3(z1);
title('x*sin(y)')
fcontour(z1);
xlabel('x')
subplot(1,2,2);
ylabel('y')
fsurf(z2);
zlabel('z')
%fmesh(z2);
grid on;
%fimplicit3(z2);
rotate3d on;
%fcontour(z2);
</source>
</source>
|}
|}




----
----
→ zurück zum Hauptartikel: [[BSE Modellierung und Simulation - SoSe26]]
→ zurück zum Hauptartikel: [[BSE Modellierung und Simulation - SoSe26]]

Aktuelle Version vom 24. April 2026, 09:12 Uhr

Autor: Prof. Dr.-Ing. Schneider

Aufgabe 2 - Plotten von diskreten Werten

  1. Erzeugen Sie zunä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 xsin(x) und xlog(x) über x.
  4. Plotten Sie nun die Kurve cos(x) über sin(x) für Winkel[0..2π] 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 z=xsin(x).
    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, figure, grid on, mesh, meshgrid, surf, surfc, plot3, axis equal, zlabel, rotate3d on



→ zurück zum Hauptartikel: BSE Modellierung und Simulation - SoSe26