ETH Zürich
Modeling and Simulating Social Systems with MATLAB
Lecture 2 – Statistics and Plotting in MATLAB
Computational Social Science
Stefano Balietti, Olivia Wolley, Dirk Helbing
Modeling and Simulating Social Systems with MATLAB Lecture 2 - - PowerPoint PPT Presentation
Modeling and Simulating Social Systems with MATLAB Lecture 2 Statistics and Plotting in MATLAB Stefano Balietti, Olivia Wolley, Dirk Helbing Computational Social Science ETH Zrich Exercise 1 Compute: 100 18 + 107 i a)
ETH Zürich
Lecture 2 – Statistics and Plotting in MATLAB
Computational Social Science
Stefano Balietti, Olivia Wolley, Dirk Helbing
Modeling and Simulating Social Systems with MATLAB 2 2
i=0 100
i=5 10
Modeling and Simulating Social Systems with MATLAB 3 3
>> (18+107)/(5*25) ans = 1
Modeling and Simulating Social Systems with MATLAB 4 4
i=0 100
>> s=sum(1:100)
>> s=sum(1:1:100)
>> s=sum(linspace(1,100))
>> s=sum(linspace(1,100,100)) s = 5050
default value default value
Modeling and Simulating Social Systems with MATLAB 5 5
i=5 10
>> s=0; >> for i=5:10 >> s=s+i^2-i; >> end >> s s = 310
Modeling and Simulating Social Systems with MATLAB 6 6
Modeling and Simulating Social Systems with MATLAB 7 7
>> A=[2 -3 -1 4; 2 3 -3 2; 2 -1 -1 -1; 2 -1 2 5]; >> b=[1; 2; 3; 4]; >> x=A\b x = 1.9755 0.3627 0.8431
>> A*x ans = 1.0000 2.0000 3.0000 4.0000
2x1−3x2−x3+4x4=1 2x1+ 3x 2−3x3+2x4=2 2x1−x2−x3−x 4=3 2x1−x2+2x3+ 5x4=4
Ax=b
Modeling and Simulating Social Systems with MATLAB 8 8
Modeling and Simulating Social Systems with MATLAB 9 9
fibonacci.m: function [v] = Fibonacci(n) v(1) = 0; if ( n>=1 ) v(2) = 1; end for i=3:n+1 v(i) = v(i-1) + v(i-2); end end >> Fibonacci(7) ans = 0 1 1 2 3 5 8 13
Modeling and Simulating Social Systems with MATLAB 10 10
fibo_rec.m: function f = fibo_rec(n) if n == 0 f(1) = 0; elseif n == 1 f(2) = 1; elseif n > 1 f = fibo_rec(n - 1); f(n + 1) = f(n) + f(n - 1); end end >> fibo_rec(7) ans = 0 1 1 2 3 5 8 13
Modeling and Simulating Social Systems with MATLAB 11 11
Modeling and Simulating Social Systems with MATLAB 12 12
Mean value: mean(x) Median value: median(x) Min/max values: min(x), max(x) Standard deviation: std(x) Variance: var(x) Covariance: cov(x) Correlation coefficient: corrcoef(x) Vector-based Matrix-based
Modeling and Simulating Social Systems with MATLAB 13 13
Modeling and Simulating Social Systems with MATLAB 14 14
Modeling and Simulating Social Systems with MATLAB 15 15
Modeling and Simulating Social Systems with MATLAB 16 16
quantity itself.
1000,…) instead of 1, 2, 3, 4.
Modeling and Simulating Social Systems with MATLAB 17 17
quantity itself.
1000,…) instead of 1, 2, 3, 4.
Same distance between 1-2-3 and 10-20-30
Modeling and Simulating Social Systems with MATLAB 18 18
?
Modeling and Simulating Social Systems with MATLAB 19 19
Modeling and Simulating Social Systems with MATLAB 20 20
Modeling and Simulating Social Systems with MATLAB 21 21
reduces this to a more manageable range.
(Weber–Fechner law)
Modeling and Simulating Social Systems with MATLAB 22 22
Modeling and Simulating Social Systems with MATLAB 23 23
Modeling and Simulating Social Systems with MATLAB 24 24
Modeling and Simulating Social Systems with MATLAB 25 25
Modeling and Simulating Social Systems with MATLAB 26 26
Modeling and Simulating Social Systems with MATLAB 27 27
Modeling and Simulating Social Systems with MATLAB 28 28
Modeling and Simulating Social Systems with MATLAB 29 29
by-n matrix and selects the pth axes object for the current plot.
window, then the second row, etc.
Modeling and Simulating Social Systems with MATLAB 30 30
We have already seen an example
last lecture. Can you reproduce it?
Modeling and Simulating Social Systems with MATLAB 31 31
processed.
Axes handle: gca
e.g. set(gcf, 'Position', [100 100 150 150]) [left bottom width height];
Modeling and Simulating Social Systems with MATLAB 32 32
http://www.mathworks.com/matlabcentral/fileexchange/23629-exportfig
export_fig('/plots/myimage.pdf', '-pdf', '-nocrop')
Modeling and Simulating Social Systems with MATLAB 33 33
Modeling and Simulating Social Systems with MATLAB 34 34
Modeling and Simulating Social Systems with MATLAB 35 35
Modeling and Simulating Social Systems with MATLAB 36 36
Modeling and Simulating Social Systems with MATLAB 37 37
Modeling and Simulating Social Systems with MATLAB 38 38
Modeling and Simulating Social Systems with MATLAB 39 39
Modeling and Simulating Social Systems with MATLAB 40 40
Modeling and Simulating Social Systems with MATLAB 41 41
Modeling and Simulating Social Systems with MATLAB 42 42
Modeling and Simulating Social Systems with MATLAB 43 43
Modeling and Simulating Social Systems with MATLAB 44 44
Modeling and Simulating Social Systems with MATLAB 45 45