• Keine Ergebnisse gefunden

1 MATLAB www.mathworks.de The MathWorks (Natick/MA/USA) Studentenversion < 100 $ SCILAB www.scilab.org Scilab Consortium (École Polytechnique ... ... Renault) kostenloses Download

N/A
N/A
Protected

Academic year: 2021

Aktie "1 MATLAB www.mathworks.de The MathWorks (Natick/MA/USA) Studentenversion < 100 $ SCILAB www.scilab.org Scilab Consortium (École Polytechnique ... ... Renault) kostenloses Download"

Copied!
20
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

1

MATLAB

www.mathworks.de

The MathWorks (Natick/MA/USA) Studentenversion < 100 $

SCILAB

www.scilab.org

Scilab Consortium (École Polytechnique ... ... Renault) kostenloses Download

(2)

MATLAB als Taschenrechner

>> 3+2 ans = 5 Funktionen

>> sqrt(25) ans = 5 Konstanten

>> pi

ans = 3.1416 Hilfe

>> help

HELP topics ...

>> help sqrt

SQRT Square root

(3)

3

Wertzuweisungen

>> a=1 a = 1

>> a=a+1 a = 2

Name = Datentyp (Wert)

>> x=int32(9.6) x = 10

>> y=3.5+2.1i

y = 3.5000 + 2.0000i

>> wort='quatsch' wort = quatsch

Datentypen:

int32 4 Byte double 8 Byte

char 2 Byte

...

(4)

Vektoren und Matrizen

>> v1=[1, 2, 3]

v1 = 1 2 3

>> v2=[1; 2; 3]

v2 = 1 2 3

>> v2'

ans = 1 2 3

>> mat=[1, 2; 3, 4]

mat=

1 2 3 4

Semikolon unterdrückt Ausgabe

>> x=x+1;

(5)

5

Verzeichnis der Variablen

>> who

a mat v1 v2 wort x y

>> whos

Name Size Bytes Class

a 1x1 8 double array mat 2x2 32 double array

v1 1x3 24 double array v2 3x1 24 double array

wort 1x7 14 char array x 1x1 4 int32 array

y 1x1 16 double array (complex)

Variablen löschen

>> clear v1

>> clear all

>> clear global

Alternative: Wird auch im Matlab workspace angezeigt

(6)

Verzeichnisse und m-Dateien

>> pwd

ans = C:\My Documents

>> dir My Music My Pictures My Videos matfiles

>> ls My Music My Pictures My Videos matfiles

>> cd 'My Music'

>> cd ..

>> cd matfiles

>> helloworld text =

Hello World

C:\My documents\matfiles\helloworld.m text = 'Hello World'

(7)

7

Rechenoperationen

>> e1=a+a e1 = 4

>> e2=a*e1 e2 = 8

>> e3=e1–e2 e3 = –4

>> e4=e2/e1 e4 = 2

>> e5=e2^2 e5 = 64

>> e6=v1*v2 e6 = 14

>> e7=v1'*v2' e7 =

1 2 3 2 4 6 3 6 9

aber

>> e8=v1*v1

??? Error using ==> mtimes

Inner matrix dimensions must agree.

aber:

>>e9=v1.*v1 e9=1 4 9

(8)

Ausgabe

>> cd matfiles

>> helloworld Hello World

>> fprintf('x = %d \n', 5) x = 5

>> fprintf('x = %f \n', 5) x = 5.000000

>> fprintf('x = %e \n', 5) x = 5.000000e+000

>> fprintf('x = %f4.2 \n', 5) x = 5.00

>> fprintf('x = %g \n', 5) x = 5

>> fprintf('x = %g \n', 0.0000005) x = 5e-007

>> text = 'aua'

>> fprintf('%s \n', text)

C:\My documents\matfiles\helloworld.m

text = 'Hello World';

disp(text) oder

fprintf('Hello World \n');

(9)

9

Eingabe

>> cd matfiles

>> wurzel

Bitte Wert eingeben: 5

Danke, die Wurzel ist 2.236068 Datei schreiben

>> fid = fopen('Wichtige_Daten.dat', 'w');

>> fprintf(fid, '%f \n',pi);

>> fclose(fid);

>> save –ascii Unwichtige_Daten.dat v1 Datei lesen

>> fid = fopen('Wichtige_Daten.dat', 'r');

>> wert = fscanf(fid,'%f');

>> fclose(fid)

>> load –ascii Unwichtige_Daten.dat

>> Unwichtige_Daten

Unwichtige_Daten = 1 2 3

C:\My documents\matfiles\wurzel.m

wert=input('Bitte Wert eingeben: ');

antwort=sqrt(wert);

fprintf('Danke, die Wurzel ist %f \n',antwort);

(10)

Schleifen

>> for k=1:5 x(k)=k^2;

end

>> x

x = 1 4 9 16 25

>> for k=1:2:5 k^2

end ans = 1 ans = 9 ans = 25

>> z=10;

>> while (z > 0) z=z–1

end z = 9 ...

z = 0

Vergleichsoperatoren

<

<=

>=

>

==

~=

(11)

11

Bedingungen

>> k = 5;

>> if (k >= 0)

fprintf('Heureka! \n') end

Heureka!

>> k = 5;

>> if (k=0) || (k>0) fprintf('Heureka! \n') end

Heureka!

>> if (k = 0) ...

elseif (k=1) ...

else

if(k>0) ...

end end

Logische Operatoren

&& und || oder ~ nicht

(12)

Matrizen erzeugen

>> mat = [1, 2; 3, 4]

mat=

1 2 3 4

Es geht auch anders

>> a(2,4) = 5 a = 0 0 0 0 0 0 0 5

>> b = zeros(2,4) b = 0 0 0 0

0 0 0 0

>> b = ones(2,4) b = 1 1 1 1

1 1 1 1

>> c = eye(2,4) c = 1 0 0 0

0 1 0 0

>> d = rand(2,4)

d = 0.93 0.79 0.46 0.63

Zufallszahlen zwischen 0 und 1

rand

rand(n,m)

normal ("Gauß-")verteilte Zufallszahlen randn(n,m)

oder auch

rand + rand + rand + rand + rand + rand + ...

rand + rand + rand + rand + rand + rand – 6.

(13)

13

Der Doppelpunkt

>> for k = 1:6 x(k)=2*k–1;

end

>> x

x = 1 3 5 7 9 11

>> x = 1:2:11

x = 1 3 5 7 9 11

>> mat = eye(4) mat = 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1

>> y = mat(3,:) y = 0 0 1 0

>> plot( mat(3,:))

(14)

Grafik plot

>> x = 1:0.1:50

>> y = sin(x)

>> plot(y)

>> plot(x,y)

>> axis( [3.0 12.0 -1.5 1.5])

>> xlabel('time')

>> ylabel('amplitude \alpha')

>> title('\alpha = sin \omega t')

>> text(7,1.1,'peak')

>> text(5,-1.2,'valley')

(15)

15

Grafik plot

>> x = 1:0.1:50

>> y = sin(x)

>> plot(x)

>> plot(y)

>> plot(x,y)

>> axis( [3.0 12.0 -1.5 1.5])

>> grid on

>> xlabel('time')

>> ylabel('amplitude \alpha')

>> title('\alpha = sin \omega t')

>> text(7,1.1,'peak')

>> text(5,-1.2,'valley')

>> y2 = sin(x-1)

>> hold

>> plot(x,y2,'r-o')

(16)

Grafik Farben

r Red y Yellow g Green b Blue c Cyan m Magenta k blacK w White Linien

- durchgezogen _ gestrichelt : Punkte

-. Strich-Punkte Symbole

+ o * x s d ^ > < p h

allgemein >> plot( x, y, 'farbe linie symbol')

(17)

17

3d-Grafik

>> plot(v)

>> mesh(v)

>> waterfall(v)

(18)

3d-Grafik

>> surf(v)

>> view( [0 90] )

>> shading interp

(19)

19

3d-Grafik

>> x = 0:0.1:20

>> plot3(cos(x),sin(x),x,'r–s')

(20)

Weitere Spielereien Ein Ton (ca. 500 Hz)

>> y = ones(10000,1);

>> for k = 1:5000 y(2*k) = -1;

end

>> sound(y,1000)

Angenehmere Töne

>> load handel

>> sound(y,Fs)

Mehrere Bilder mit subplot

>> subplot(2,1,1)

>> plot(y)

>> subplot(2,1,2)

Ha- le- luja ha- le- luja haleluja haleluja ha- le- lu- jaaa

Abbildung

Grafik  plot  &gt;&gt; x = 1:0.1:50  &gt;&gt; y = sin(x)  &gt;&gt; plot(y)  &gt;&gt; plot(x,y)  &gt;&gt; axis( [3.0 12.0 -1.5 1.5])  &gt;&gt; xlabel('time')  &gt;&gt; ylabel('amplitude \alpha')
Grafik  Farben  r    Red  y   Yellow  g   Green  b   Blue  c   Cyan  m  Magenta  k   blacK  w  White  Linien  -     durchgezogen  _    gestrichelt  :     Punkte  -

Referenzen

ÄHNLICHE DOKUMENTE

ENHANCE analysis identified three channels through which economic instruments can contribute to risk management: (1) direct risk reduction: for example, risk financing

In chapter 3, the meteorological model ARPS is tested in a neutral atmospheric boundary layer, over a flat rough terrain in order to check the turbulence models available in ARPS:

Der Natura 2000-Managementplan für das Fauna-Flora-Habitat-Gebiet 7214-342 „Bruch bei Bühl und Baden-Baden“ und die Vogelschutzgebiete 7214-441 „Riedmatten und Schiftunger

Six cas de figures sont analysés: la protection d'un nom de forte renommée, la démarcation de produits très concurrencés, la promotion d'un nom de faible renommée, le

• Micro-plot experiments: Determination of the effect of the transgenes on the resistance reaction against powdery mildew and of the ecological consequences of the introgression

Mitunter wird der Begriff Ecole de Paris, über dessen Sinn und Unsinn ab Mitte der 50er Jahre in Paris selbst heftig gestritten wurde, aber auch »fast univer­.. sal«4 verwendet

Die Tabelle 1 im Anhang enthält die wesentlichen in den Leistungsvereinbarungen definierten Pflichten der Stiftung BWOe und der ETH. Den aktuell gültigen Vertrag vom 9. Oktober

The combination of two tunable optical devices allows MQP-SCLM to integrate seven different imaging modalities within a single microscopic system, including bright field, dark