1 / 27

MATLAB Afslutning

MATLAB Afslutning. Anders P. Ravn Institut for Datalogi Aalborg Universitet Forår 2005. MATLAB. Hvorfor? Hvordan?. Et værktøj til tekniske beregninger. Analyse og modellering af data Simulering af modeller. Værktøjskasser osv. Andre muligheder. Lommeregner Regneark (Excel) Maple

niran
Download Presentation

MATLAB Afslutning

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. MATLAB Afslutning Anders P. Ravn Institut for Datalogi Aalborg Universitet Forår 2005

  2. MATLAB • Hvorfor? • Hvordan?

  3. Et værktøj til tekniske beregninger • Analyse og modellering af data • Simulering af modeller

  4. Værktøjskasser osv.

  5. Andre muligheder • Lommeregner • Regneark (Excel) • Maple • MathCad • SAS • … Brug det rigtige værktøj til opgaven

  6. Structures v1= struct('Varenavn', 'Papirclips', 'Pris', 19.95) v1 = Varenavn: 'Papirclips' Pris: 19.9500

  7. En ny stuktur >>v1= struct('Varenavn', 'Papirclips', 'Pris', 19.95) v1 = Varenavn: 'Papirclips' Pris: 19.9500 >>v2 = v1; v2.Varenavn = 'Elastikker'; v2.Pris= 17.50; >>v2 v2 = Varenavn: 'Elastikker' Pris: 17.5000

  8. En database >> v3 = v1; v3.Varenavn = 'Tape'; v3.Pris= 9.25; v3 v3 = Varenavn: 'Tape' Pris: 9.2500 >> lager = [v1 v2 v3] lager = 1x3 struct array with fields: Varenavn Pris >> lager(2).Pris ans = 17.5000

  9. En database-operation function pris=findpris(varelager,vare) for v = varelager if strcmp(v.Varenavn,vare) pris= v.Pris; return; end end pris = -1 m-fil >> findpris(lager,'Tape') ans = 17.5000

  10. Data analyse – fiskeskiver

  11. p Positionsbestemmelse p = [x , y] w1 = [a,b] -- lokalt A = [ cos(theta) sin(theta) -sin(theta) cos(theta) ] wl GLOBAL = ( p’ + A*w1’)’ M1 ? M1‘ = p ‘+ X*w1’

  12. p Løsningsforsøg M1‘ = p ‘+ X*w1’ X = (M1‘ - p ‘)/w1’ » p = [1 1]; » w1 = [1 0.5]; » M = [1.5 0]; » (M' - p')/w1' ans = 0.5000 0 -1.0000 0

  13. Bedre forsøg M1‘ = p ‘+ X*w1’ X= [ cos(theta) sin(theta) -sin(theta) cos(theta) ] f(theta) = M1‘ - p‘ - X *w1’ Dvs . f(theta) = [ 0 0]’ Husk så at for vektor a gælder: a*a’ = |a|2 Dvs. Vi kan finde minimum for z(theta) = f(theta) * f(theta)’ function r = fz(theta) global M p w1; X = [cos(theta), sin(theta); -sin(theta), cos(theta)]; f = M' - p' - X*w1'; r = f'*f;

  14. p Løsning » global p M w1 » p = [1 1]; » w1 = [1 0.5]; » M = [1.5 0]; » fmin('fz', 0, 2*pi) ans = 1.5708 » ans/pi ans = 0.5000 » M = [0 0]; » fmin('fz', 0, 2*pi) ans = 2.8198 » ans/pi ans = 0.8976

  15. Eksempel function r = fz(x) global M p w1; X = [cos(x), sin(x); -sin(x), cos(x)]; r1 = M' - p' - X*w1'; r = r1'*r1; » global M w1 p » M = [1.5 0] » w1 = [1 0.5] » p = [1 1] » fmin('fz',0,pi)/pi ans = 0.5000 fz(ans*pi) ans = 1.2326e-032

  16. Billeder B = imread('image.bmp','bmp') ; » size(B) ans = 1008 886 3 » image(B)

  17. Billedbehandling » Udsnit = B(101:104, 301:304, :) Udsnit(:,:,1) = 188 183 176 182 198 182 172 172 188 195 173 159 185 188 169 156 Udsnit(:,:,2) = 183 168 162 172 190 172 169 167 179 185 172 158 179 179 166 151 Udsnit(:,:,3) = 179 163 159 171 187 163 162 163 174 176 167 153 167 170 157 147 » image(Udsnit);

  18. Forbrænding Et kulpartikel brænder: - Nogle dele er dækket af en askeflage - Andre dele er glød Hvordan udvikler det sig ?

  19. En model function Pnext = step(P,f) % Simulering af forbrænding: emne er matrix P % med glød = 1 % aske = 0 % Sandsynlighed for glød i næste trin % afhænger af om naboer er ens, samt en % koefficient f. % Naboer regnes cyklisk.

  20. Algoritmen function Pnext = step(P,f) d = size(P); Pnext = zeros(d); for i = 1:d(1), for j = 1:d(2), n = P(op(i,d(1)), j ); e = P(i, ned(j,d(2)) ); s = P(ned(i,s(1)), j ); v = P(i, op(j,d(2)) ); if (2+n+sy+e+v)*f*rand > 0.5, Pnext(i,j) = 1; end; end; end; function r = ned(k,n); r = k-1; if r == 0, r = n; end; function r = op(k,n); r = k+1; if r > n, r = 1; end;

  21. Simulering P = rand(7, 8) > 0.5; pcolor(P); P = step(P, 0.5); pcolor(P); …

  22. Simpel Ind- og Udlæsning » help iofun File import/export functions. load - Load workspace from MAT-file. save - Save workspace to MAT-file. ... Command window I/O clc - Clear command window. home - Send cursor home. disp - Display array. input - Prompt for user input. pause - Wait for user response.

  23. Formatteret Ind- og Udlæsning File opening and closing. fopen - Open file. fclose - Close file. Formatted file I/O. fscanf - Read formatted data from file. fprintf - Write formatted data to file. ...

  24. Formater The format specifier : % [- | + | 0] [Field Width][.Precision] Format Character "-" aligns output left (usually, it's right-aligned). "+" outputs a plus sign for positive numbers (usually, it is supressed). “0” outputs leading zeroes. The field width specifies the overall field length. The precision specifies the length of the fractional part for floating point numbers. If omitted, the default is 6. The format character determines the base type for the formatted values: "d": integer value in decimal format. "f": floating point value in fixed format (xxx.yyyyyy). "e": floating point value in scientific format (0.yyyyyye+zzz). "E": floating point value in scientific format (0.yyyyyyE+zzz). "s": String.

  25. Eksempel fprintf(red_file,'Jordens radius: %9.0f m\n',R); fprintf(red_file,'Refraktionskoefficient: %9.2f\n',k); fprintf(red_file,'\r\n'); fprintf(red_file,' Fra Til V Sd ih sh S d_H\n'); fprintf(red_file,' gon m m m m m\n'); Jordens radius: 6386000 m Refraktionskoefficient: 0.13 Fra Til V Sd ih sh S d_H gon m m m m m

  26. Eksempel … fprintf(red_file,'%5.0f %5.0f %9.4f %9.3f %9.3f %9.3f %9.3f%9.3f\n',linie); 5007 5001 99.8900 307.762 1.640 1.555 307.762 0.623

  27. Nu til Øvelser • Saml op på tidligere øvelser • Kig på opgave

More Related