Matlab Octave Zklady programovania pre fyzikov Rozren dtov
Matlab / Octave Základy programovania pre fyzikov
Rozšírené dátové štruktúry – bunkové pole • Cell array - bunkové pole – je to pole resp. matica, ale jeho prvky môžu byť rôzneho typu
Rozšírené dátové štruktúry – bunkové pole Inicializácia bunkového poľa: a=cell(1, 3) a{1, 1}='hello'; a{1, 2}=[1 5 8 2]; a{1, 2}= rand(3, 2); alebo a={'hello', [1 5 8 2], rand(3, 2)}; Prístup k hodnotám
Rozšírené dátové štruktúry – štruktúra • Structure – štruktúra – spojené názvy premenných aj ich hodnoty do jednej štruktúry – objektovo orientované programovanie Inicializácia - nie je nutná, ale vhodná, ak to bude veľká štruktúra: s = struct([]); s = struct('meno', {}, 'znamky', {}, 'rok', {}); Pridanie prvkov – môže byť rôzneho typu, aj ďalšia štruktúra: s. meno = 'Peter Veľký'; s. znamky = [1 2 1]; s. rok = '2012';
Rozšírené dátové štruktúry – štruktúra Príklad inicializácie štruktúry, kde zadáme páry názvov a hodnôt jednotlivých prvkov: Ø teraz je person štruktúra s prvkami name, age, child. Age
Figure Handles – identifikátor obrázka Každý grafický objekt má identifikátor (aj napr. súbor pri čítaní a zápise) L=plot(1: 10, rand(1, 10)); získame identifikátor vytvoreného grafu A=gca; získame identifikátor osí F=gcf; získame identifikátor posledného obrázku Zistenie parametrov grafu - get(L); y. Vals=get(L, 'YData‘); zistenie všetkých parametrov načítali sme z grafu ypsilonové dáta Nastavenie parametrov grafu - set(A, 'Font. Name', 'Arial', 'XScale', 'log'); set(L, 'Line. Width', 1. 5, 'Marker', '*'); üVšetko, čo vidíme na grafe sa dá zmeniť pomocou identifikátor grafu, identifikátor je štruktúra, v ktorej sú zapísané všetky vlastnosti objektu
Figure Handles – identifikátor obrázka üVšetko, čo vidíme na grafe sa dá zmeniť pomocou identifikátor grafu, identifikátor je štruktúra, v ktorej sú zapísané všetky vlastnosti objektu
Ako rýchlo beží script? tic resetuje interný časovač toc vypíše hodnotu uplynutého času od resetu v sekundách Príklad: tic Sada. Prikazov 1 a=toc; Sada. Prikazov 2 b=toc;
Symbolické výpočty • vyžaduje Symbolic Math Toolbox • pre Octave existuje tiež toolbox pre symbolické výpočty alebo 1/3 a 4/5 ostane zlomkom počas celého výpočtu sym - kľúčové slovo pre definovanie symbolickej premennej, ktorej presnú hodnotu nemusíme zadať - program pracuje len so symbolom – názvom tejto premennej
Symbolické výpočty expand – symbolická expanzia výrazu tak, aby vo výsledku každá základná funkcia mala len jeden argument
Symbolické výpočty simplify – pokúsi sa zjednodušiť symbolický subs – zamení premenné hodnotami alebo iným symbolickým výrazom
Symbolické výpočty int – integrovanie, určitý aj neurčitý integrál diff – derivovanie
Symbolické výpočty solve – riešenie rovníc a sústavy rovníc Pozor: v starších verziách je potrebné rovnice zapísať v úvodzovkách solve('a*x^2 + b*x + c', 'b') S = solve('x + y = 1', 'x - 11*y = 5');
- Slides: 13