%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% File:         uebung_grundlagen_e.m
%
% Description:  Exercise for MATLAB Simulink 
%               MATLAB Basics
%
% Date:         31.03.12
% Author:       Ulrich Wohlfarth
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

echo on;
format compact;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Variables

% a) 

skalar = 10

% b) 

skalar*pi

% c) 
                                                                     
skalar = ans

% d) 

help log

doc log

% e) 

1 / 0           % inf: Unendlich
0 / 0           % NaN: Nicht definiert

% f) 

t=2
skalar = sin(t) * exp(-t)

% g) 

whos

% h) 

clear 


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Vectors and matrices

% a) 

v = 0:2:10

% b) 

w = (0:-1:-5)'

% c) 

v + w'
v - w'

% d) 

(v + w').*(v - w')

% e) 

m = [ v ; w' ] 

% f) 

mm = m(:,end-2:end)

% g) 

size(mm)

% h) 

mm = [mm(:,2) mm(:,1) mm(:,3)]
mm(:,1:2) = [mm(:,2) mm(:,1) ]

% i) 

linspace(0,10,5)

% j) 

logspace(-2,2,5)

% k) 

eye(3)


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Structures

% a) 
student = struct('name','Wohlfarth','christianname','Ulrich','age',41)

student.name            = 'Wohlfarth' 
student.christianname   = 'Ulrich' 
student.age             = 41 

% b) 

student(2).name         = 'Prof. Raps' 
student(2).christianname= 'Franz' 
student(2).age          = 50 


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Relational and logical operators

% a) 
a = 0 ;
b = 1 ;

~(~a & ~b)
not(and(not(a),not(b)))

% b) 

~(~a | ~b)
not(or(not(a),not(b)))

% c) 

a=[0 0 1 1]';
b=[0 1 0 1]';

[a , b , not(and(not(a),not(b))) , not(or(not(a),not(b))), a|b , a&b]

% d) 

exist('c','var')

% e) 

exist('bode')

% f) 

v = -3:3 ;
v(v<0) = v(v<0)*2

% g) 

find(v>=0)


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% control and loop statements

% a) 

for i=1:10, if mod(i,2)==0, disp('+'), else disp('-'), end, end 

% b) 

a = 1; b = 0;
while abs(a-b)>=0.2, a=rand; b=rand; abs(a-b), end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% MATLAB scripts und functions

% a) 

[a,s,m,d] = basic_calc(3,2)

% b) 

b = 1:3 
c = 1./b 
[a,s,m,d] = basic_calc(b,c)

% c) 

[k,g,m] = minmax (1:100)
