sudo apt-get install octave octave-gsl octave-miscellaneous octave-statistics gnuplot printf("Hallo Welt!\n"); a = 2; b = 5; a+b a-b a*b a/b a sqrt(a) format long sqrt(a) sqrt=2; sqrt(a) clear sqrt sqrt(a) a = [1,2,3,4]; b = [10,20,30,40]; a+b a*b a.*b a./b sum(a) mean(a) a(1) printf("Value at a(1): %d\n",a(1)); % %d:decimal, %f: float sqrt(a(4)); function y = euklid(a,b) y = sqrt(sum((a-b).*(a-b))); end %read csv X = dlmread ("/home/c/Dropbox/uebung/dm/uebung1/octave/test.txt", ","); X(1,1) printf("Value at (1,1): %d\n",y); X(2,3) X(:,1) X(1,:) size(X) size(X)(1,2) size(X)(1,1) length(X) %transposed X' c=[1,2,3,3,2,1] length(c) find(c==1) find(c==2) unique(c) rand(3,2) zeros(2,10) ones(5,3) for y = c printf("%d\n",y); end %useful matrix/vector constructors d = 0:10 for i=d printf("%d\n",i); end i=0; while i < 10 printf("%d\n",i++); end i+=1 %Danger: loops are slow!! %Because commands always are interpreted during run time, not precompiled! %(Just in Time compiler can be used) x = (0.01:0.01:1)'; y= sin(2*pi*x) + normrnd(0,0.1,100,1); x1=(0:0.01:1)'; plot(x,y,'.o', x1, sin(2*pi*x1), '-') p = polyfit (x,y,1); z = polyval(p, x1); plot(x,y,'.o', x, sin(2*pi*x), '-', x1, z, '-') x = [0,1,2,2]; x1 = [-1:0.1:5]; y= [1,1,1,2]; plot(x,y,'.o',"markersize",30) axis([-1,5,-1,5]) p = polyfit (x,y,1); z = polyval(p, x1); plot(x,y,'.o','markersize',30, x1, z, '-') axis([-1,5,-1,5]) %plot some data x = [91, 92, 90, 92, 90, 89, 91, 89, 90, 100, 100, 100]; [x, i, j] = unique (x); y = accumarray(j', 1); axis([min(x)-1 max(x)+1 0 max(y)+1]) xlabel('x-axis') ylabel('y-axis') title('plot title') legend('plot legend') plot(x,y,"@11","markersize",30) print('-dsvg','figure.svg') function y = cosim(a,b) y = sum(a.*b)/( sqrt(sum(a.*a))* sqrt(sum(b.*b)) ); end A = [1,2,3;4,5,6;7,8,9]; [V,D] = eig(A); A*V V*D