MATLAB matrični laboratorij Interaktivni alat (kalkulator), programski jezik, grafički procesor

Size: px
Start display at page:

Download "MATLAB matrični laboratorij Interaktivni alat (kalkulator), programski jezik, grafički procesor"

Transcription

1 M. Essert: Matlab interaktivno 1 MATLAB matrični laboratorij Interaktivni alat (kalkulator), programski jezik, grafički procesor Program = algoritam + strukture podataka TIPOVI PODATAKA temeljni tip - kompleksna matrica brojevi - double (s pretvorbama u integer-e (u)int8,16,32,64 ) nepopunjena matrica - sparse znak i niz znakova unutar jednostrukih navodnika - char, string ćelija - cell, polje različitih tipova struktura - struct, polje različitih tipova funkcijski tip - function (funkcija kao argument) objekti - Java i INLINE object. KONSTANTE I VARIJABLE pi i,j - kompleksne veličine, sqrt(-1) eps - relativna točnost, najmanji iznos između dva realna broja inf, NaN - beskonačno (infinitum) i nije broj (not a number) realmax, realmin - najveći i najmanji realni broj bitmax - najveći cijeli broj (floating point) integer. ans - varijabla odgovora (ansver) ime_varijable - alfanumerički niz znakova, početni znak slovo, bez posebnih znakova, osjetljivost na velika i mala slova. Jednom definirana varijabla x može se ispisati jednostavnim pozivom imena x i tipke enter (return). FUNKCIJA Poziv: [iz1, iz2,...] = ime_funkcije (ul1, ul2,...) Definicija: Function [iz1, iz2,...] = ime_funkcije (ul1, ul2,...) gdje su: ul1, ul2,... - ulazni argumenti u funkciju iz1, iz2,... - izlazna rješenja funkcije (potprograma) ugrađene (bilt-in function) abs(), sin(), sqrt(), exp(),... ZAGRADE ( ) - grupiranje izraza, grupiranje funkcijskih argumenata, indeksiranje vektora (matrica) [ ] - grupiranje vektorskih (matričnih) elemenata { } - ćelije = polja različitih tipova podataka s klasičnim indeksiranjem

2 2 M. Essert: Matlab interaktivno RADNO OKRUŽENJE Command window radni prozor Workspace memorijski radni prostor (who varijable) Current directory trenutačni radni prostor Command history povijesni redoslijed naredbi File->New->M-file (CTRL+N) editor za m-datoteke ZNAKOVI NA NAREDBENOJ LINIJI >> - Matlabov upit korisniku, engl. prompt, - odvajanje naredbi ; - sprječavanje ispisa rezultata... - nastavak naredbe u idućoj liniji % - komentar (od znaka udesno) POČETAK RADA help - poziva pomoć help ops - pomoć o operatorima help format pomoć o formatima help elfun pomoć o elementarnim funkcijama... intro - uvod o Matlabu demo - demonstracija primjera lookfor - pretraživanje pojmova CTRL+C - prekid izvođenja diary - vođenje dnevnika rada quit - završetak rada OPERATORI Arithmetički operatori = - pridružba, assignment plus, uplus - plus, unarni plus + minus, uminus - minus, unarni minus - mtimes - matrično množenje * mldivide - matrično dijeljenje s lijeva \ mrdivide - matrično dijeljenje s desna / mpower - matrično potenciranje ^ Točka. - decimalna točka pristup polju strukture, npr. A(i).field Operatori nad elementima - upotreba Hadamard-ovog ('točka', engl. 'dot') operatora. power - potenciranje nad poljem.^ times - množenje elemenata u polju.* ldivide - lijevo dijeljenje u polju.\ rdivide - desno dijeljenje u polju./

3 M. Essert: Matlab interaktivno 3 C=A.*B znači C=A./B znači C=A.\B znači C=A.^B znači C=A.^r znači C=r.^A znači c(i,j)=a(i,j)b(i,j) c(i,j)=a(i,j)/b(i,j) c(i,j)=b(i,j)/a(i,j) c(i,j)=a(i,j)^{b(i,j)} c(i,j)=a(i,j)^r, r je broj. c(i,j)=r^{a(i,j)} Relacijski operatori eq - jednako == ne - nejednako ~= lt - manje nego < gt - veće nego > le - manje ili jednako <= ge - veće ili jednako >= Logički operatori logički I (AND) među izrazima && logički ILI (OR) među izrazima and - logički I (AND) elemenata & or - logički ILI (OR) elemenata not - logički NE (NOT) ~ xor - logički exclusivni ILI (XOR) any - Istina (True, 1) ako je bilo koji element vektora različit od nule all - Istina (True, 1) ako su svi elementi vektora različit od nule Operatori na razini bita bitand - I (AND) na razini bita. bitcmp - komplement bitova. bitor - ILI (OR) na razini bita. bitxor - EX-ILI (XOR) na razini bita. bitset - Postavi bit bitget - Provjeri bit. bitshift - Pomak (shift) bitova. Operatori skupova union - unija skupova. unique - jedincatost (unique) skupa. intersect - presjek (intersection) skupova. setdiff - razlika (difference) skupova. setxor - Ex-Ili (exclusive-or) skupova. ismember - Istina (True) ako član (member) skupa. STRING NIZ ZNAKOVA 'nesto' - niz znakova (nesto), string SISTEMSKI ZNAKOVI.. - prethodni directorij, roditeljski (parent) folder! - pozivanje sistemske naredbe

4 4 M. Essert: Matlab interaktivno ZNAKOVI S VEKTORIMA (MATRICAMA) horzcat - [a b], [a, b] nadoveza elemenata u retku. vertcat - [a; b] stupčana nadoveza elemenata. transpose -.' za transpoziciju vektora (matrice) ctranspose - ' kompleksno konjugirana transpozicija colon - : ili dvotočje, za raspon vrijednosti argumenata SLOŽENI PODACI Structures spline, solve, diff. i optimisation solvers, OOP; Cells varargin, vargout, text in graphics, switch-case; Polje struktura: ime(1...dim).polje_x ili struct('polje_x',{podaci}) Polje ćelija: Ime_polja_celija={elem 1, elem 2,..., elem n } Poziv: Ime_polja_celija{element/-i} Primjeri 1. a=[1 2 3] c=[4; 5; 6] a*c dot(a,c) b=a' A=c*a a*a a.*a b=a.^2 a.*b exp(a) log(ans) sqrt(a) format long sqrt(a) format 2^(-24) n=4; testmat(1).ime='hilbert'; testmat(1).mat=hilb(n); testmat(2).ime='pascal'; testmat(2).mat=pascal(n); testmat(1).mat testmat(2).ime Moja_celija={pi*n, magic(3); 'Mario radi', rand(5)} Moja_celija{4} Moja_celija{4}(2,1) Cellplot(Moja_celija) Moja_celija{2}(1,3) NEKE ELEMENTARNE MATEMATIČKE FUNKCIJE Trigonometrijske sin, sinh asin, asinh cos, cosh acos, acosh tan, tanh atan, atanh atan2 sec, sech asec, asech - sinus, hiperbolični sinus - inverzni sinus, inverzni hiperbolični sinus - kosinus, hiperbolični kosinus - inverzni kosinus, inverzni hiperb. kosinus - tangens, hiperbolični tangens - inverzni tangens, inverzni hiperb. tangens - inverzni tangens u četvrtom kvadrantu - sekans, hiperbolični sekans - inverzni sekans, inverzni hiperbolični sekans

5 M. Essert: Matlab interaktivno 5 csc, csch acsc, acsch cot, coth acot, acoth - sekans, hiperbolični sekans - inverzni kosekans, inverzni hiperb. kosekans - kotangens, hiperbolični kotangens - inverzni kotangens,inverzni hiperb. kotangens Eksponencijalne exp log log10 - eksponencijalna - prirodni logaritam. - obični (baza 10) logaritam log2 - logaritam po bazi 2 pow2 - potencija po bazi 2 realsqrt - kvadratni korijen broja >= 0 sqrt - kvadratni korijen Kompleksne abs angle complex conj imag real isreal - apsolutna vrijednost - fazni kut - Komplesni broj iz realnog i imaginarnog dijela - Konjugirani kompleksni broj - Imaginarni dio kompleksnog broja - realni dio kompleksnog broja - True (istina) za realna polja Zaokruživanje i ostatak fix - zaokruživanje prema nuli floor - zaokruživanje prema minus beskonačnom ceil - zaokruživanje prema plus beskonačnom round - zaokruživanje na najbliži cijeli broj mod - modulo funkcija (kao rezultat ostatka dijeljenja). rem - ostatak nakon dijeljenja sign - funkcija predznaka TVORBA VEKTORA a) Utipkavanje elemenata vektora unutar [] ili programsko generiranje s pomoću petlje (engl. loop). b) Tvorba s rubovima i razmakom {početak} : {korak} : {dočetak} ako je korak=1 može se pisati samo {početak} : {dočetak} Korak može biti i negativan, a ako je pritom 'početak' manji od 'dočetka' onda će generirani vektor biti prazan ([]). c) preko funkcija 'linspace()' i 'logspace()' U oba slučaja prva dva argumenta su početak i dočetak vektora (u drugom kao potencije broja 10), a treći je broj elemenata između njih. Razlika je što su prvi linearno, a drugi logaritamski udaljeni jedni od drugih.

6 6 M. Essert: Matlab interaktivno CRTANJE help plot PLOT Linear plot. PLOT(X,Y) crta vektor Y prema vektoru X. Različite tipovi linija, simbola i boja mogu se postići s naredbom PLOT(X,Y,S) gdje je S niz znakova (string) dobiven iz bilo kojeg od tri(ili svih) stupaca ispod: b plava. točka - čvrsto g zelena o kružić : točkasto r crvena x x-znak -. crt_točka c cyan + plus -- crtkano m magenta * zvijezda y žuta s kvadratić k crna d romb v trokut (dolje) ^ trokut (gore) < trokut (lijevo) > trokut (desno) p pentagram h hexagram Na primjer, PLOT(X,Y,'c+:') crta cyan točkastu liniju s + znakom na svakoj točki; PLOT(X,Y,'bd') crta rombove na svakoj točki podatka, ali ih ne povezuje linijom. PLOT(X1,Y1,S1,X2,Y2,S2,X3,Y3,S3,...) kombinira grafove definirane trojcima (X,Y,S), gdje su X i Y vektori ili matrice, a S su stringovi. Na primjer, PLOT(X,Y,'y-',X,Y,'go') crta podatke dvaput, s punom žutom linijom interpolirajući zelenim kružićima točke podataka. Uz Plot() obično se koriste i funkcije: title('tekst') dodaje tekst na vrh grafa. xlabel('tekst'), ylabel('tekst') dodaje tekst uz X-os ili Y-os. text(x,y,'string') dodaje string u navodnicima na (X,Y) poziciju. subplot(nmk) crta k-ti podgraf u (n x m) matrici grafova Primjeri x = linspace(0,1,11) ; y = sin(2*pi*x) ; plot(x,y) 2.2 x=logspace(.01,1,15); y=log(x); plot(x,y,x,y,'*')

7 M. Essert: Matlab interaktivno %Generiranje signala sa 'šumom' (noise): x=0:.025:2; y=sin(pi*x); yn=y+.25*(rand(size(x)) -.5); plot(x,y,'--',x,yn) title(['crtkana linija: sin(pi*x),'... ' cvrsta linija: podaci sa šumom']) xlabel(['šum je slucajan iz [-1/8,1/8]']) 2.4 %Ubrzanje računanja preko odsječaka: m=5; n=4*m+1; x=linspace(0,1,n) ; % [x(1),x(2),... x(21)], x(j)-x(j-1)=.05 y=zeros(1,n); xf=x( 1:(2*m+1) ) ; % the values [0,.05,...,.5] y(1:(2*m+1))=sin(2*pi*xf); y( (2*m+2):n )= -y(2:(2*m+1)) ; % koristi se činjenica da je % sin(x+pi)=-sin(x) plot(x,y) Ključno je ovo: ako je J=[J(1),J(2),...,J(k)] vektor indeksa vektora x=[x(1),x(2),...,x(n)], onda je w=x(j) vektor w= [x(j(1)),...,x(j(k))]. TVORBA MATRICA 1. Mogu se utipkati elementi: npr. A=[2 4 5; 2 6 3; -l 6 2] što daje 3 x 3 matricu. Ulazni podaci se tipkaju u redu (elementi se odvajaju prazninom ili zarezom), a s točkom-zarez (;) deklarira se početak novog retka. S naredbom rand(n) ili rand(n,m) generira se matrica reda (n x n) odnosno (n x m) sa slučajnim elementima koji su raspršeni preko normalne razdiobe između 0 i Naredbe a=fix(10*rand(5)) b=round(10*rand(5)) generiraju 5x5 matrice s cjelobrojnim elementima. Ako su A = [d ij ] i B = [b ij ] (n x m) matrice i C = [c ij ] je (m x p) matrica, onda imamo sljedeće matrične aritmetičke operacije: (a) A + B = [a ij + b ij ] i A B = [a ij - b ij ] (b) A * C = D gdje je D (n x p) matrica s veličinama dobivenim matričnim množenjem. 3. Općenito za (n x m) matricu A vrijedi: (a) veličina (tj. broj redaka i stupaca) dobiva se kao [n,m]=size(a) (b) i-ti redak je A(i,:) (c) j-ti stupac je A(:,j) (d) podmatrica B sa i do j redaka i p do q stupaca je B=A(i:j,p:q)

8 8 M. Essert: Matlab interaktivno Primjeri A=[1 2 5 ; ] B=[4 2 0 ; 4 2-7] C=[3 6 ; -2 1 ;-4 2] A+B A*C 3*A 3.2 A=[3 1;5 2] A^2, A^3 A^(-1), inv(a) A*A^(-1) C=A^(-2) C*A^2 3.3 A=[1 2; 3 4]; B=[1 2; 2 4] T1= A == B T2= A <= B T3= A > B T4= A <= 3 T5= A ~= B T1=[1 1; 0 1]; T2=[1 0; 0 0] T=T1 & T2 T=T1 T2 T=~T1 bitand(13,7) bitxor(13,7) 3.4 Inverz matrice Matrica ima inverz ako joj je determinanta različita od nule. A=[3 1; 5 2] d=det(a) Problem određivanja kada kvadratna matrica ima inverz nema lak odgovor. A=[3 1; 5 2] B=[3 1; 6 2] Matrica A nije singularna onda i samo onda kad vrijedi jedno od slijedećih zaključaka: (a) det A 0 det (A) det (B) (b) Reducirani 'row echelon' forma od A je identitet rref(a) rref(b) (c) A ima inverz inv(a) inv(b) (d) Jedino rješenje jednadžbe Ax = 0 je x = 0, tj., nul-prostor je nul-vektor. Matlab naredba "null" računa bazu za nul-prostor. Primjetite da ona ne ispisuje nul-vektor. null(a) null(b) (e) Matrica A ima puni rang. Ako je A reda (n x n) onda je rang od A jednak n. rank(a) rank(b) Neke matrične funkcije size( ) - veličina matrice, broj redaka i stupaca ' - transpozicija matrice diag() - dijagonalna matrica eye() - jedinična (identity) matrica zeros() - nul matrica sparse(i,j,v) - sparse matrica, na (i,j) mjestu v-ti element

9 M. Essert: Matlab interaktivno 9 Polinomi kao matrice roots - nalazi korijen polinioma poly - pretvara korijen u polinom Primjeri 4. A=[5 7 9; 1-3, -7] B=[-1,2,5;9 0 5] C=[0,1;3,-2;4,2] D=[1:5; 6:10; 11:2:20] size(a) size(ans) [r c]=size(a'), S=size(A') D, D' size(d), size(d') P=ones(2,3) Z=zeros(2,3), zeros(size(p')) S=[2-1 0; ; 0-1 2] St=S' S-St I=eye(3), x=[8; -4; 1], I*x D=[-3 0 0; 0 4 0; 0 0 2] diag(d) d=[-3 4-2], D=diag(d) F=[ ; ; ] diag(f) x=[8; -4; 1] G=[C x] A, B, H=[A;B] J=[1:4; 5:8; 9:12; ] K=[diag(1:4) J; J' zeros(4,4)] spy(k),grid J(1,1), J(2,3), J(4,5) J(4,1)=J(1,1)+6 J(1,1)=J(1+1)-3*J(1,2) J(:,3) J(:,2:3) J(4,:) J(2:3,2:3) A,B,A.*B A.*C A.*C' i=[1,3,5]; j=[2,3,4]; v=[ ] S=sparse(i,j,v) T=full(S) roots([1-3 2]) poly(ans) KONTROLNE STRUKTURE PROGRAMIRANJA INPUT naredba: x=input('neki tekst') dozvoljava interaktivan unos za x varijablu u izvođenju programa. Na zaslonu se pritom ispisuje neki tekst. x=input('neki tekst',s) sprema uneseni tekst kao string u varijablu x. IF kontrolna struktura odgovara na pitanje ako onda inače: if {relacija} {naredbe} ili još općenitije: if {relacija} {naredbe} elseif { relacija } { naredbe } else { naredbe }

10 10 M. Essert: Matlab interaktivno SWITCH struktura izabire vrijednost između više ponuđenih izraza. switch {izraz} case {slučaj_1}, naredba,..., naredba case {slučaj2, slučaj3,...} naredba,..., naredba... otherwise, naredba,..., naredba Izraz može biti skalar ili string. Postoji dva tipa petlji: (a) for petlja. Sintaksa je for {varijabla} = {vektor vrijednosti brojila} {naredba/-e} (b) while petlja odgovara na pitanje 'sve dok je istina čini': while {relacije} {naredbe} Programske funkcije: break - završava izvođenje for ili while petlje continue - prebacuje kontrolu na iduću iteraciju petlje try - početak TRY bloka catch - početak CATCH bloka eval - izvršava string s MATLAB izrazom. feval - izračunava funkciju specificiranu stringom run - izvršava script-a function global return nargin nargout varargin varargout disp fprintf sprintf pause error warning - dodaje novu (korisničku) funkciju - definira globalne varijable - povratak iz pozvane funkcije - broj ulaznih argumenata funkcije - broj izlaznih argumenata funkcije - lista promjenljive duljine ulaznih argumenata - lista promjenljive duljine izlaznih argumenata - ispis polja (obično stringa) - ispis formatirane poruke - ispis formatirane poruke u string - čekanje na korisnikov odziv (pauza) - ispis pogreške poruke ili prekidne funkcije - prikaz poruke upozorenjawarning message

11 M. Essert: Matlab interaktivno 11 Primjeri for i=1:3 x(i)=i^2 5.2 for i=1:5 for j=1:5 a(i,j)=1/(i+j) aa=hilb (5) 5.3 n=4 clear A for i=1:n for j=1:n if i < j A(i,j)=-1; elseif i > j A(i,j)=0; else A(i,j)=1; A AA=eye(n)-triu(ones(n),1) 5.4 j=1 while j <= 10 k(j)=cos(j*pi); j=j+1; k % usporedi sa: kk=cos((1:10)*pi) 5.5 x=(1:5)*2*pi; sprintf(' %5.3f',x) x=(1:5)*2*pi; sprintf(' %5.3f\n',x) 5.6 n=input(' unesi cijeli broj n = '); v=(1:2:n).^2 5.7 % Naći najmanji pozitivni % cijeli broj q za koji % vrijedi 2 -q = 0: x=1; q=0; while x>0 x=x/2; q=q+1; q 5.8 % Naći najmanji cijeli broj p % tako daje p = 1 % u aritmetici s pomičnim % zarezom: x=1; p=0; y=1; z=x+y; while x~=z y=y/2; p=p+1; z=x+y; p 2*y eps Primjetite da 2*y daje najmanji realni broj različit od nule u Matlab-u, tj. eps. 5.9 method = 'bilinear'; switch lower(method) case {'linear','bilinear'} disp('method is linear') case 'cubic' disp('method is cubic') case 'nearest' disp('method is nearest') otherwise disp('unknown method.')

12 12 M. Essert: Matlab programski 5.10 %Formatirani ispis dobiva se upotrebom sprintf funkcije: disp('n sum(1:n) n*(n+1)/2 ') disp(' ') for n=1:10 disp(sprintf(' %3.0f %5.0f %5.0f'...,n,sum(1:n),n*(n+1)/2)); 5.11 % Script file SineTable.m % % Ispisuje kratku tablicu proračuna sinusa. % n = 21; x = linspace(0,1,n); y = sin(2*pi*x); disp(' ') disp(' k x(k) sin(x(k))') disp(' ') for k=1:21 degrees = (k-1)*360/(n-1); disp(sprintf(' %2.0f %3.0f %6.3f'...,k,degrees,y(k))); disp( ' '); disp('x(k) je dan u stupnjevima.') disp(sprintf('jedan stupanj = %5.3e radijana',pi/180)) 5.12 % Script File Zoom % % Nacrtajte (x-1)^6 uz točku x=1 sa % slijedno povećanom skalom. % Izračunavanje (x-1)^6 preko % x^6-6x^5 + 15x^4-20x^3 + 15x^2-6x +1 % dovodi do ozbiljnih promišljanja. close all k=0; for delta = [ ] x = linspace(1-delta,1+delta,100)'; y = x.^6-6*x.^5 + 15*x.^4-20*x.^ *x.^2-6*x + ones(100,1); k=k+1; subplot(2,3,k) plot(x,y,x,zeros(1,100)) axis([1-delta 1+delta -max(abs(y)) max(abs(y))])

13 M. Essert: Matlab programski 13 SCRIPTA 6.1 ime1.m h=input('korak h= '); x=0:h:2; y=x.^2 2*x+1; y1=sin(x); plot(x,y,'r-.',x,y1,'g:<') 6.2 ime2.m h=input('korak h= '); x=0:h:pi; y=cos(x).*(x<=pi/2)+(-x+pi/2).*(x>pi/2); plot(x,y) 6.3 epicikloida.m a=12; b=5; t=0:0.005:10*pi; x=(a+b)*cos(t)-b*cos((a/b+1)*t); y=(a+b)*sin(t)-b*sin((a/b+1)*t); plot(x,y) axis equal axis ([ ]) grid on title('epicikloida: a=12, b=5') xlabel('x(t)'), ylabel('y(t)') 6.4 % ovo je test m-datoteka nazvana test.m h=input('mesh size h = '); x=(0:h:1); lx=length(x); y=x.^2; int=(h/2)*(y(1)+2*sum(y(2:(lx-1)))+y(lx) ) % trapezno pravilo za integral s egzaktnom vrijednošću 1/3 Računalna matematika, FSB Zagreb, 2008.

14 14 M. Essert: Matlab programski INLINE FUNKCIJA 6.5 f=inline('exp(x)-1'),f(2) f=inline('log(a*x)/(1+y^2)') f=inline('log(a*x)/(1+y^2)','x','y','a') 6.6 fd_deriv.m function y=fd_deriv(f,x,h) %FD_DERIV Aproksimacija derivacije if nargin < 3, h=sqrt(eps); y=(feval(f,x+h) -feval(f,x))/h; f=inline('exp(-x)/(1+x^2)'); fd_deriv(f,pi) M-FUNKCIJE FUNCTION dodaje novu funkciju. Nove funkcije sadržavaju stare, a spremaju se u datoteku s imenom istim kao ime funkcije, uz ekstenziju '.m'. Početak datoteke je sintaktički čvrsto određen. Komentar poslije funkcijske definicije koristi se u help-u. Primjer: function [mean,stdev] = stat(x) %STAT Interesting statistics. n = length(x); mean = sum(x) / n; stdev = sqrt(sum((x - mean).^2)/n); Podfunkcija (subfunction) koja je vidljiva drugim funkcijama unutar iste datoteke definira se nakon već napisane funkcije. function [mean,stdev] = stat(x) %STAT Interesting statistics. n = length(x); mean = avg(x,n); stdev = sqrt(sum((x-avg(x,n)).^2)/n); % function mean = avg(x,n) %MEAN subfunction mean = sum(x)/n; Podfunkcije nisu vidljive izvan datoteke u kojoj su definirane.

15 M. Essert: Matlab programski maxentry.m function y=maxentry(a) %MAXENTRY Nalazi najveci broj u matrici A y=max(max(abs(a))); maxentry([1 2; 11-4; 8 2]) 6.8 area.m function [A]=area(a,b,c) %Izračunava površinu trokuta koji ima stranice % dužine a, b i c % Inputs: % a, b,c duljine stranica % Output: % A površina trokuta % Usage: % Pov = area(2,3,4) % Napisao M.M., FSB Zagreb, s = (a+b+c)/2; A=sqrt(s*(s-a)*(s-b)*(s-c)); 6.9 flogist.m function [f,fprime]=flogist(x,a) %FLOGIST logističa funkcija i njena derivacija f= x.* (1-a*x); fprime=1-2*a*x; f=flogist(2,.1) [f,fprime]=flogist(2,.1) flogist(1:4,2) 6.10 comfun.m function comfun(x,y,z) %COMFUN prikaz funkcije s tri string argumenta disp(x), disp(y) disp(z) comfun('ab','ac','ad') comfun ab cd eg disp('hello'), disp hello diary ('moja.txt'), diary moja.txt sqrt 2 % sto nam daje???? Računalna matematika, FSB Zagreb, 2008.

16 16 M. Essert: Matlab programski 6.11 marks.m function [x_sort, x_mean, x_med, x_std]=marks(x) % MARKS statistička analiza vektora x_sort=sort(x); if nargout>1, x_mean=mean(x); if nargout>2, x_med=median(x); if nargout>3, x_std=std(x); marks([ ]) [a,b]=marks([ ]) [a,b,c]=marks([ ]) [a,b,c,d]=marks([ ]) 6.12 defn.m function z=defn(x,y) z=-x*y; moja5-16.m clear % ovaj program poziva funkciju de_fn.m a=input('lijeva krajnja točka a = '); b=input('desna krajnja točka b = '); N=input(' broj podintervala, N = '); ya=input('početna vrijednost u x=a, ya= '); h=(b-a)/n; x=a+h*(1:(n+1)); lx=length(x); y(1)=ya; for j=1:n y(j+1)=y(j)+h*defn(x(j),y(j)); plot(x,y) 6.13 function [x,iter]=sqrt_newton(a,tol) % SQRT_NEWTON - traženje kvadratnog korijena Newtonovom metodom % X=SQRT_NEWTON(A,TOL) vraća X kao rješenje korijena koji je >= 0 % TOL je tolerancija konvergencije (pretpostavljena je EPS) % [X, ITER]=SQRT_NEWTON(A,TOL) vraća također i broj iteracija ITER if nargin < 2, tol=eps; x=a; iter=0; xdiff=inf; fprintf(' k x_k rel_promjena\n') while xdiff>tol iter=iter+1; xold=x; x=(x+a/x)/2;

17 M. Essert: Matlab programski 17 xdiff=abs(x-xold)/abs(x); fprintf('%2.0f: %20.16e %9.2e\n',iter,x,xdiff) if iter>50 error('ne konvergira nakon 50 iteracija!') REKURZIVNE FUNKCIJE 6.14 function koch(pl,pr,level) %KOCH Recursively generated Koch curve. % KOCH(PL, PR, LEVEL) recursively generates a Koch curve, % where PL and PR are the current left and right points % and LEVEL is the level of recursion if level==0 plot([pl(1),pr(1)], [pl(2),pr(2)]); %Join pl and pr hold on else A=(sqrt(3)/6)*[0 1; -1 0]; % Rotate/scale matrix pmidl=(2*pl + pr)/3; koch(pl,pmidl,level-1) % Left branch ptop=(pl + pr)/2 + A*(pl-pr); koch(pmidl,ptop,level-1) pmidr=(pl + 2*pr)/3; koch(ptop,pmidr,level-1) koch(pmidr, pr, level-1) % Left mid branch % Right mid branch % Right branch a) pl=[0;0]; pr=[1;0]; for k=1:4 subplot(2,2,k) koch(pl,pr,k) axis('equal') title(['koch curve: level = ', num2str(k)], 'FontSize',16) b) level=4; edges=7; for k=1:edges pl=[cos(2*k*pi/edges); sin(2*k*pi/edges)]; pr=[cos(2*(k+1)*pi/edges); sin(2*(k+1)*pi/edges)]; koch(pl,pr,level) axis('equal') title('koch snowflake','fontsize',16,'fontangle','italic') Računalna matematika, FSB Zagreb, 2008.

18 18 M. Essert: Matlab programski Fibonacci sequence 6.15 a) function f = Fib1(n) % Returns the nth number in the % Fibonacci sequence. F=zeros(1,n+1); F(2) = 1; for i = 3:n+1 F(i) = F(i-1) + F(i-2); f = F(n); b) function f = Fib2(n) % Returns the nth number in the % Fibonacci sequence. if n==1 f = 0; elseif n==2 f = 1; else f1 = 0; f2 = 1; for i = 2:n-1 f = f1 + f2; f1=f2; f2 = f; c) function f = Fib3(n) % Returns the nth number in the % Fibonacci sequence. if n==1 f = 0; elseif n==2 f = 1; else f = Fib3(n-1) + Fib3(n-2); d) function f = Fib4(n) % Returns the nth number in the % Fibonacci sequence. A = [0 1;1 1]; y = A^n*[1;0]; f=y(1);

19 M. Essert: Matlab programski 19 FUNKCIJE S VARIJABILNIM BROJEM ARGUMENATA 6.16 Moments.m function varargout=moments(x) %MOMENTS Moments of a vector. % [m1,m2,...,m_k]=moments(x) returns the first, second,..., % k'th moments of the vector X, where the j'th moment % is SUM(X.^j)/LENGTH(X). for j=1:nargout, varargout(j)={sum(x.^j)/length(x)}; >> m1=moments(1:4) m1 = >> [m1,m2,m3]=moments(1:4) 6.17 companb.m function C=companb(varargin) %COMPANB Block companion matrix % C=COMPANB(A_1,A_2,...,A_m) is the block companion matrix % corresponeding to the n-by-n matrices A_1,A_2,...,A_m. m=nargin; n=length(varargin{1}); C=diag(ones(n*(m-1),1),-n); for j=1:m Aj=varargin{j}; C(1:n,(j-1)*n+1:j*n)= -Aj; >> X=ones(2); C=companb(X,2*X,3*X) C = Računalna matematika, FSB Zagreb, 2008.

20 20 M. Essert: Matlab programski POLINOMI 6.18 Legeandre-ovi polinomi zadani su rekurzivnom jednadžbom: (n+1)p (n+1) (x)=(2n+1)xp n (x) np n-1 (x), P 0 =0; Nacrtajte prva četiri Legeandrova polinoma. Legre.m x=-1:.01:1; p1=x; p2=(3/2)*x.^2-1/2; p3=(5/2)*x.^3-(3/2)*x; p4=(35/8)*x.^4-(15/4)*x.^2+3/8; plot(x,p1,'r:',x,p2,'g--',x,p3,'b-.',x,p4,'m-') box off leg('\itn=1','n=2','n=3','n=4',4) xlabel('x','fontsize',12,'fontangle','italic') ylabel('p_n','fontsize',12,'fontangle','italic') title('legre Polynomials','FontSize',14) text(-.6,.7,'(n+1)p_{n+1}(x)=(2n+1)x P_n(x) - n P_{n-1}(x)',... 'FontSize',12,'FontAngle','Italic') Primjetite: leg-a se može pozicionirati uz pomoć zadnjeg argumenta: -1: nadesno od crteža, 0: automatski (na 'najboljoj' poziciji), 1: gore desno (pretpostavljena vrijednost), 2: gore lijevo; 3: dolje lijevo, 4: dolje desno. Polinom n-tog reda: y=p(x)= a 1 x n + a 2 x n a n x 1 + a n+1 uz poznate koeficijente [a 1 a 2... a n a n1 ] za poznatu vrijednost x može se izračunati direktno po gornjoj formuli: poli.m y=0; n=length(a)-1; for k = 1:n + 1 y = y + a(k)*x.^(n-k+1) >> a=[2-7 -2]; x=3; dok za više vrijednosti, područje vrijednosti x-a, program se samo proširuje vektorom y vrijednosti: polinom.m n = length(a)-1; nx = length(x); y = zeros(1,nx); for k = 1:n + 1 y = y + a(k)*x.^(n-k+1) >> a=[2-7 -2]; x=[3:.2:10];

21 M. Essert: Matlab programski 21 Isto se može načiniti i s pomoću funkcije polyval. >> help polyfun polyval polyfit polyder polyint conv deconv spline - izračunava polinom - traži koeficijente polinoma koji predstavlja podatke - derivira polinom - integrira polinom analitički - množi polinome - dijeli polinome - interpolira kubični spline % korijeni (nule) polinoma P = [ ]; %polinom roots(p) ans = i i r = ans; PP = poly(r) PP = % množenje polinoma a = [ ]; b = [4 9 16]; c = conv(a,b) c = % vrijednost polinoma u točki(-ama) polyval(a, 2) ans = 26 polyval(a, [ ]) Fitting Zadano je m-točaka: { X i, Y i } m I=1 Treba naći polinom p stupnja n tako da je p(x i ) priblžno jednako y i za sve i=1:m. To se postiže funkcijom polyfit koja za zadani red polinoma n daje koeficijente polinoma p tako da je suma od i=1:m za kvadrat razlike odsupanja (p(x i )-y i ) 2 minimalna. x = [ ]; %fitting y = [ ]; polyfit(x,y,2) ans = Nađite polinom trećeg reda koji u 20 točaka u intervalu [-2,2] po metodi najmanjih kvadrata aproksimira funkciju f(x)=1/(x+(1-x)^2). x=linspace(-2,2,20); Računalna matematika, FSB Zagreb, 2008.

22 22 M. Essert: Matlab programski y=1./(x+(1-x).^2); p=polyfit(x,y,3); plot(x,y,'*',x,polyval(p,x),' '); Objasnite dobivene koeficijente polinoma p: Nađite egzaktnu interpolacija zadanih podataka preko spline funkcije. x=linspace(-2,2,20); y=1./(x+(1-x).^2); xx=linspace(-2,2,60); yy=spline(x,y,xx); plot(x,y,'*',xx,yy,' ') 6.19 polifit.m p=[ ]; x=0:.25:4; y=polyval(p,x)+randn(1,length(x)); plot(x,y, * ), Title( Ulazni podaci ), pause while 1 n=input( Red polinoma n= ); if n<=0, break, c=polyfit(x,y,n) fit=polyval(c,x) plot(x,fit,x,y, o ), pause 6.20 inter.m xd = 1 : 4; yd = [ ]; x = 1 : 0.1 : 4; y = polyval(polyfit(xd,yd,length(xd)-1),x); plot(x,y,xd,yd,'o')

Mathcad sa algoritmima

Mathcad sa algoritmima P R I M J E R I P R I M J E R I Mathcad sa algoritmima NAREDBE - elementarne obrade - sekvence Primjer 1 Napraviti algoritam za sabiranje dva broja. NAREDBE - elementarne obrade - sekvence Primjer 1 POČETAK

More information

Sveučilišni studijski centar za stručne studije. Zavod za matematiku i fiziku. Uvod u Matlab. Verzija 1.1

Sveučilišni studijski centar za stručne studije. Zavod za matematiku i fiziku. Uvod u Matlab. Verzija 1.1 Sveučilišni studijski centar za stručne studije Zavod za matematiku i fiziku Uvod u Matlab Verzija 1.1 Karmen Rivier, Arijana Burazin Mišura 1.11.2008 Uvod Matlab je interaktivni sistem namijenjen izvođenju

More information

Projektovanje paralelnih algoritama II

Projektovanje paralelnih algoritama II Projektovanje paralelnih algoritama II Primeri paralelnih algoritama, I deo Paralelni algoritmi za množenje matrica 1 Algoritmi za množenje matrica Ovde su data tri paralelna algoritma: Direktan algoritam

More information

AUTOMATIZACIJA AUTOMATIZACIJA. Proces kontrole i upravljanja zahtijeva kontinuirano mjerenje. znanje i informacije. Osnovni tipovi sustava

AUTOMATIZACIJA AUTOMATIZACIJA. Proces kontrole i upravljanja zahtijeva kontinuirano mjerenje. znanje i informacije. Osnovni tipovi sustava AUTOMATIZACIJA Laboratorijske vježbe MatLab/Simulink (Octave, Scilab) 1.Uvod u MatLab (Octave, Scilab) 2.Matematičko modeliranje komponenti sustava 3.Matlab (Octave, Scilab) u analizi automatskih sustava

More information

TEORIJA SKUPOVA Zadaci

TEORIJA SKUPOVA Zadaci TEORIJA SKUPOVA Zadai LOGIKA 1 I. godina 1. Zapišite simbolima: ( x nije element skupa S (b) d je član skupa S () F je podskup slupa S (d) Skup S sadrži skup R 2. Neka je S { x;2x 6} = = i neka je b =

More information

ENGR Spring Exam 2

ENGR Spring Exam 2 ENGR 1300 Spring 013 Exam INSTRUCTIONS: Duration: 60 minutes Keep your eyes on your own work! Keep your work covered at all times! 1. Each student is responsible for following directions. Read carefully..

More information

PRIPADNOST RJEŠENJA KVADRATNE JEDNAČINE DANOM INTERVALU

PRIPADNOST RJEŠENJA KVADRATNE JEDNAČINE DANOM INTERVALU MAT KOL Banja Luka) ISSN 0354 6969 p) ISSN 1986 58 o) Vol. XXI )015) 105 115 http://www.imvibl.org/dmbl/dmbl.htm PRIPADNOST RJEŠENJA KVADRATNE JEDNAČINE DANOM INTERVALU Bernadin Ibrahimpašić 1 Senka Ibrahimpašić

More information

ZANIMLJIV NAČIN IZRAČUNAVANJA NEKIH GRANIČNIH VRIJEDNOSTI FUNKCIJA. Šefket Arslanagić, Sarajevo, BiH

ZANIMLJIV NAČIN IZRAČUNAVANJA NEKIH GRANIČNIH VRIJEDNOSTI FUNKCIJA. Šefket Arslanagić, Sarajevo, BiH MAT-KOL (Banja Luka) XXIII ()(7), -7 http://wwwimviblorg/dmbl/dmblhtm DOI: 75/МК7A ISSN 5-6969 (o) ISSN 986-588 (o) ZANIMLJIV NAČIN IZRAČUNAVANJA NEKIH GRANIČNIH VRIJEDNOSTI FUNKCIJA Šefket Arslanagić,

More information

January 18, 2008 Steve Gu. Reference: Eta Kappa Nu, UCLA Iota Gamma Chapter, Introduction to MATLAB,

January 18, 2008 Steve Gu. Reference: Eta Kappa Nu, UCLA Iota Gamma Chapter, Introduction to MATLAB, Introduction to MATLAB January 18, 2008 Steve Gu Reference: Eta Kappa Nu, UCLA Iota Gamma Chapter, Introduction to MATLAB, Part I: Basics MATLAB Environment Getting Help Variables Vectors, Matrices, and

More information

MATLAB for Chemical Engineering

MATLAB for Chemical Engineering MATLAB for Chemical Engineering Dr. M. Subramanian Associate Professor Department of Chemical Engineering Sri Sivasubramaniya Nadar College of Engineering OMR, Chennai 603110 msubbu.in[at]gmail.com 16

More information

Algoritam za množenje ulančanih matrica. Alen Kosanović Prirodoslovno-matematički fakultet Matematički odsjek

Algoritam za množenje ulančanih matrica. Alen Kosanović Prirodoslovno-matematički fakultet Matematički odsjek Algoritam za množenje ulančanih matrica Alen Kosanović Prirodoslovno-matematički fakultet Matematički odsjek O problemu (1) Neka je A 1, A 2,, A n niz ulančanih matrica duljine n N, gdje su dimenzije matrice

More information

Metode izračunavanja determinanti matrica n-tog reda

Metode izračunavanja determinanti matrica n-tog reda Osječki matematički list 10(2010), 31 42 31 STUDENTSKA RUBRIKA Metode izračunavanja determinanti matrica n-tog reda Damira Keček Sažetak U članku su opisane metode izračunavanja determinanti matrica n-tog

More information

Ivan Soldo. Sažetak. U članku se analiziraju različiti načini množenja matrica. Svaki od njih ilustriran je primjerom.

Ivan Soldo. Sažetak. U članku se analiziraju različiti načini množenja matrica. Svaki od njih ilustriran je primjerom. Osječki matematički list 5(005), 8 Različiti načini množenja matrica Ivan Soldo Sažetak U članku se analiziraju različiti načini množenja matrica Svaki od njih ilustriran je primjerom Ključne riječi: linearni

More information

TOPIC 2 Computer application for manipulating matrix using MATLAB

TOPIC 2 Computer application for manipulating matrix using MATLAB YOGYAKARTA STATE UNIVERSITY MATHEMATICS AND NATURAL SCIENCES FACULTY MATHEMATICS EDUCATION STUDY PROGRAM TOPIC 2 Computer application for manipulating matrix using MATLAB Definition of Matrices in MATLAB

More information

SIGNALS AND LINEAR SYSTEMS LABORATORY EELE Experiment (2) Introduction to MATLAB - Part (2) Prepared by:

SIGNALS AND LINEAR SYSTEMS LABORATORY EELE Experiment (2) Introduction to MATLAB - Part (2) Prepared by: The Islamic University of Gaza Faculty of Engineering Electrical Engineering Department SIGNALS AND LINEAR SYSTEMS LABORATORY EELE 110 Experiment () Introduction to MATLAB - Part () Prepared by: Eng. Mohammed

More information

LINEARNI MODELI STATISTIČKI PRAKTIKUM 2 2. VJEŽBE

LINEARNI MODELI STATISTIČKI PRAKTIKUM 2 2. VJEŽBE LINEARNI MODELI STATISTIČKI PRAKTIKUM 2 2. VJEŽBE Linearni model Promatramo jednodimenzionalni linearni model. Y = β 0 + p β k x k + ε k=1 x 1, x 2,..., x p - varijable poticaja (kontrolirane) ε - sl.

More information

A Mini course on MATLAB

A Mini course on MATLAB A Mini course on MATLAB MATLAB Basics, Matrix Algebra and Scripting Arun K. Tangirala 1 1 Department of Chemical Engineering Indian Institute of Technology Madras Mini Course on MATLAB A.K. Tangirala (IIT

More information

Introduction to MATLAB

Introduction to MATLAB Introduction to MATLAB Macroeconomics Vivaldo Mendes Dep. Economics Instituto Universitário de Lisboa September 2017 (Vivaldo Mendes ISCTE-IUL ) Macroeconomics September 2013 1 / 41 Summary 1 Introduction

More information

Using MATLAB. Linear Algebra

Using MATLAB. Linear Algebra Using MATLAB in Linear Algebra Edward Neuman Department of Mathematics Southern Illinois University at Carbondale One of the nice features of MATLAB is its ease of computations with vectors and matrices.

More information

Manual of Time Scales Toolbox for MATLAB

Manual of Time Scales Toolbox for MATLAB Manual of Time Scales Toolbox for MATLAB BAYLOR UNIVERSITY WACO, TX 76798 2005 Baylor University User s Manual: Time Scales Toolbox for MatLab Written By: Brian Ballard Bumni Otegbade This project funded

More information

Šime Šuljić. Funkcije. Zadavanje funkcije i područje definicije. š2004š 1

Šime Šuljić. Funkcije. Zadavanje funkcije i područje definicije. š2004š 1 Šime Šuljić Funkcije Zadavanje funkcije i područje definicije š2004š 1 Iz povijesti Dvojica Francuza, Pierre de Fermat i Rene Descartes, posebno su zadužila matematiku unijevši ideju koordinatne metode

More information

PREDAVANJA. Igor Vujović. Split, 2016.

PREDAVANJA. Igor Vujović. Split, 2016. SVEUČILIŠTE U SPLITU POMORSKI FAKULTET U SPLITU TEHNIČKI PROGRAMSKI PAKETI PREDAVANJA Igor Vujović Split, 2016. PREDGOVOR Danas se smatra da tehnički obrazovana osoba mora imati određena znanja iz programiranja

More information

Lecture 4: Linear Algebra Review, Part III

Lecture 4: Linear Algebra Review, Part III Lecture 4: Linear Algebra Review, Part III Brian Borchers February 1, 000 1 Vector Norms Although the conventional Euclidean length is most commonly used, there are alternative ways to measure the length

More information

3. Array and Matrix Operations

3. Array and Matrix Operations 3. Array and Matrix Operations Almost anything you learned about in your linear algebra classmatlab has a command to do. Here is a brief summary of the most useful ones for physics. In MATLAB matrices

More information

Kratak kurs MatLab-a

Kratak kurs MatLab-a Kratak kurs MatLab-a 1 SADRŽAJ 1. Uvodne osnove... 3 2. Rad sa osnovnim funkcijama MatLab-a... 4 2.1. Matematičke funkcije u MatLabu... 5 2.2. Rad sa matricama... 6 2.2.1. Rad sa elementima matrice...

More information

Lab 2: Static Response, Cantilevered Beam

Lab 2: Static Response, Cantilevered Beam Contents 1 Lab 2: Static Response, Cantilevered Beam 3 1.1 Objectives.......................................... 3 1.2 Scalars, Vectors and Matrices (Allen Downey)...................... 3 1.2.1 Attribution.....................................

More information

6. PROGRAMSKE STRUKTURE STRUKTUIRANOG PROGRAMIRANJA

6. PROGRAMSKE STRUKTURE STRUKTUIRANOG PROGRAMIRANJA 6. PROGRAMSKE STRUKTURE STRUKTUIRANOG PROGRAMIRANJA U programiranju često postoji potreba da se redoslijed izvršavanja naredbi uslovi prethodno dobivenim međurezultatima u toku izvršavanja programa. Na

More information

O MATLAB-U Što je MATLAB? MATLAB je naročito dobar za. Elektrotehnika. Kako se i gdje sve Matlab koristi u tehnici?

O MATLAB-U Što je MATLAB? MATLAB je naročito dobar za. Elektrotehnika. Kako se i gdje sve Matlab koristi u tehnici? O MATLAB-U Što je MATLAB? MATLAB je jedan od nekolicine komercijalnih matematičkih software paketa/alata Postoje još i Maple Mathematica MathCad MATLAB je naročito dobar za Matematičke operacije Posebno

More information

Simetrične matrice, kvadratne forme i matrične norme

Simetrične matrice, kvadratne forme i matrične norme Sveučilište JJStrossmayera u Osijeku Odjel za matematiku Sveučilišni preddiplomski studij matematike Martina Dorić Simetrične matrice, kvadratne forme i matrične norme Završni rad Osijek, 2014 Sveučilište

More information

CISE 302 Linear Control Systems Laboratory Manual

CISE 302 Linear Control Systems Laboratory Manual King Fahd University of Petroleum & Minerals CISE 302 Linear Control Systems Laboratory Manual Systems Engineering Department Revised - September 2012 2 Lab Experiment 1: Using MATLAB for Control Systems

More information

L3: Review of linear algebra and MATLAB

L3: Review of linear algebra and MATLAB L3: Review of linear algebra and MATLAB Vector and matrix notation Vectors Matrices Vector spaces Linear transformations Eigenvalues and eigenvectors MATLAB primer CSCE 666 Pattern Analysis Ricardo Gutierrez-Osuna

More information

MATLAB Examples. Mathematics. Hans-Petter Halvorsen, M.Sc.

MATLAB Examples. Mathematics. Hans-Petter Halvorsen, M.Sc. MATLAB Examples Mathematics Hans-Petter Halvorsen, M.Sc. Mathematics with MATLAB MATLAB is a powerful tool for mathematical calculations. Type help elfun (elementary math functions) in the Command window

More information

Optimization and Calculus

Optimization and Calculus Optimization and Calculus To begin, there is a close relationship between finding the roots to a function and optimizing a function. In the former case, we solve for x. In the latter, we solve: g(x) =

More information

Math 307: Problems for section 3.1

Math 307: Problems for section 3.1 Math 307: Problems for section 3.. Show that if P is an orthogonal projection matrix, then P x x for every x. Use this inequality to prove the Cauchy Schwarz inequality x y x y. If P is an orthogonal projection

More information

ALGORITAM FAKTORIZACIJE GNFS

ALGORITAM FAKTORIZACIJE GNFS SVEUČILIŠTE U ZAGREBU FAKULTET ELEKTROTEHNIKE I RAČUNARSTVA ALGORITAM FAKTORIZACIJE GNFS Ivan Fratrić Seminar iz predmeta Sigurnost računalnih sustava ZAGREB, Sažetak Faktorizacija brojeva jedan je od

More information

Uvod u relacione baze podataka

Uvod u relacione baze podataka Uvod u relacione baze podataka Ana Spasić 2. čas 1 Mala studentska baza dosije (indeks, ime, prezime, datum rodjenja, mesto rodjenja, datum upisa) predmet (id predmeta, sifra, naziv, bodovi) ispitni rok

More information

Introduction to MatLab

Introduction to MatLab Introduction to MatLab 1 Introduction to MatLab Graduiertenkolleg Kognitive Neurobiologie Friday, 05 November 2004 Thuseday, 09 Novemer 2004 Kurt Bräuer Institut für Theoretische Physik, Universität Tübingen

More information

+ MATRIX VARIABLES AND TWO DIMENSIONAL ARRAYS

+ MATRIX VARIABLES AND TWO DIMENSIONAL ARRAYS + MATRIX VARIABLES AND TWO DIMENSIONAL ARRAYS Matrices are organized rows and columns of numbers that mathematical operations can be performed on. MATLAB is organized around the rules of matrix operations.

More information

4 Funkcije. 4.1 Definicija funkcije

4 Funkcije. 4.1 Definicija funkcije Definicija funkcije Poziv funkcije Funkcijski parametri Pozicijski parametri Slijedni parametri Imenovani parametri Funkcija je objekt Funkcijski prostor imena Ugnjež dene funkcije Rekurzivne funkcije

More information

Matlab Section. November 8, 2005

Matlab Section. November 8, 2005 Matlab Section November 8, 2005 1 1 General commands Clear all variables from memory : clear all Close all figure windows : close all Save a variable in.mat format : save filename name of variable Load

More information

1.1 Uvod. 1.1 Uvod Značajke programskog jezika Python Interpretacija me dukôda

1.1 Uvod. 1.1 Uvod Značajke programskog jezika Python Interpretacija me dukôda 1.1 Uvod 7 1.1 Uvod 1.1.1 Zašto Python? Python je interpreterski, interaktivni, objektno orjentirani programski jezik, kojeg je 1990. godine zamislio Guido van Rossum. Već do konca 1998., Python je imao

More information

In this LAB you will explore the following topics using MATLAB. Investigate properties of the column space of a matrix.

In this LAB you will explore the following topics using MATLAB. Investigate properties of the column space of a matrix. MATH 22AL Lab # 6 Objectives In this LAB you will explore the following topics using MATLAB. Investigate properties of the null space of a matrix. Learn how to find a basis for null-space of a matrix.

More information

Matlab for Review. NDSU Matlab Review pg 1

Matlab for Review. NDSU Matlab Review pg 1 NDSU Matlab Review pg 1 Becoming familiar with MATLAB The console The editor The graphics windows The help menu Saving your data (diary) General environment and the console Matlab for Review Simple numerical

More information

Computational Foundations of Cognitive Science

Computational Foundations of Cognitive Science Computational Foundations of Cognitive Science Lecture 14: Inverses and Eigenvectors in Matlab; Plotting and Graphics Frank Keller School of Informatics University of Edinburgh keller@inf.ed.ac.uk February

More information

Input: A set (x i -yy i ) data. Output: Function value at arbitrary point x. What for x = 1.2?

Input: A set (x i -yy i ) data. Output: Function value at arbitrary point x. What for x = 1.2? Applied Numerical Analysis Interpolation Lecturer: Emad Fatemizadeh Interpolation Input: A set (x i -yy i ) data. Output: Function value at arbitrary point x. 0 1 4 1-3 3 9 What for x = 1.? Interpolation

More information

An Introduction to MatLab

An Introduction to MatLab Introduction to MatLab 1 An Introduction to MatLab Contents 1. Starting MatLab... 3 2. Workspace and m-files... 4 3. Help... 5 4. Vectors and Matrices... 5 5. Objects... 8 6. Plots... 10 7. Statistics...

More information

3. Programiranje u Matlab-u

3. Programiranje u Matlab-u 3. Programiranje u Matlab-u 3.1 M-datoteke M-datoteka nije ništa drugo do obična tekstualna datoteka koja sadrži MATLAB komande i sačuvana je sa ekstenzijom.m. Postoje dva tipa M-datoteka, skriptovi i

More information

ALGORITMI. Pojam algoritma Blok dijagram

ALGORITMI. Pojam algoritma Blok dijagram ALGORITMI Pojam algoritma Blok dijagram UVOD U ALGORITME Sadržaj Pojam algoritma Primjeri algoritama Osnovna svojstva algoritama Pojam algoritma Što je algoritam? Grubo rečeno: Algoritam = metoda, postupak,

More information

Linear Algebra March 16, 2019

Linear Algebra March 16, 2019 Linear Algebra March 16, 2019 2 Contents 0.1 Notation................................ 4 1 Systems of linear equations, and matrices 5 1.1 Systems of linear equations..................... 5 1.2 Augmented

More information

Homework 2 - Solutions MA/CS 375, Fall 2005

Homework 2 - Solutions MA/CS 375, Fall 2005 Homework 2 - Solutions MA/CS 375, Fall 2005 1. Use the bisection method, Newton s method, and the Matlab R function fzero to compute a positive real number x satisfying: sinh x = cos x. For each of the

More information

MATH.2720 Introduction to Programming with MATLAB Vector and Matrix Algebra

MATH.2720 Introduction to Programming with MATLAB Vector and Matrix Algebra MATH.2720 Introduction to Programming with MATLAB Vector and Matrix Algebra A. Vectors A vector is a quantity that has both magnitude and direction, like velocity. The location of a vector is irrelevant;

More information

Hornerov algoritam i primjene

Hornerov algoritam i primjene Osječki matematički list 7(2007), 99 106 99 STUDENTSKA RUBRIKA Hornerov algoritam i primjene Zoran Tomljanović Sažetak. U ovom članku obrad uje se Hornerov algoritam za efikasno računanje vrijednosti polinoma

More information

Chapter 3 Differentiation Rules (continued)

Chapter 3 Differentiation Rules (continued) Chapter 3 Differentiation Rules (continued) Sec 3.5: Implicit Differentiation (continued) Implicit Differentiation What if you want to find the slope of the tangent line to a curve that is not the graph

More information

Solutions to Systems of Linear Equations

Solutions to Systems of Linear Equations Solutions to Systems of Linear Equations 5 Overview In this chapter we studying the solution of sets of simultaneous linear equations using matrix methods. The first section considers the graphical interpretation

More information

Numerical solution of ODEs

Numerical solution of ODEs Péter Nagy, Csaba Hős 2015. H-1111, Budapest, Műegyetem rkp. 3. D building. 3 rd floor Tel: 00 36 1 463 16 80 Fax: 00 36 1 463 30 91 www.hds.bme.hu Table of contents Homework Introduction to Matlab programming

More information

Lecture 4: Matrices. Math 98, Spring Math 98, Spring 2018 Lecture 4: Matrices 1 / 20

Lecture 4: Matrices. Math 98, Spring Math 98, Spring 2018 Lecture 4: Matrices 1 / 20 Lecture 4: Matrices Math 98, Spring 2018 Math 98, Spring 2018 Lecture 4: Matrices 1 / 20 Reminders Instructor: Eric Hallman Login:!cmfmath98 Password: c@1analog Class Website: https://math.berkeley.edu/~ehallman/98-fa18/

More information

SECTION 2: VECTORS AND MATRICES. ENGR 112 Introduction to Engineering Computing

SECTION 2: VECTORS AND MATRICES. ENGR 112 Introduction to Engineering Computing SECTION 2: VECTORS AND MATRICES ENGR 112 Introduction to Engineering Computing 2 Vectors and Matrices The MAT in MATLAB 3 MATLAB The MATrix (not MAThematics) LABoratory MATLAB assumes all numeric variables

More information

Introduction to Matlab

Introduction to Matlab History of Matlab Starting Matlab Matrix operation Introduction to Matlab Useful commands in linear algebra Scripts-M file Use Matlab to explore the notion of span and the geometry of eigenvalues and eigenvectors.

More information

Identity Matrix: EDU> eye(3) ans = Matrix of Ones: EDU> ones(2,3) ans =

Identity Matrix: EDU> eye(3) ans = Matrix of Ones: EDU> ones(2,3) ans = Very Basic MATLAB Peter J. Olver October, 2003 Matrices: Type your matrix as follows: Use, or space to separate entries, and ; or return after each row. EDU> [;5 0-3 6;; - 5 ] or EDU> [,5,6,-9;5,0,-3,6;7,8,5,0;-,,5,]

More information

Classes 6. Scilab: Symbolic and numerical calculations

Classes 6. Scilab: Symbolic and numerical calculations Classes 6. Scilab: Symbolic and numerical calculations Note: When copying and pasting, you need to delete pasted single quotation marks and type them manually for each occurrence. 6.1 Creating polynomials

More information

Slika 1. Slika 2. Da ne bismo stalno izbacivali elemente iz skupa, mi ćemo napraviti još jedan niz markirano, gde će

Slika 1. Slika 2. Da ne bismo stalno izbacivali elemente iz skupa, mi ćemo napraviti još jedan niz markirano, gde će Permutacije Zadatak. U vreći se nalazi n loptica različitih boja. Iz vreće izvlačimo redom jednu po jednu lopticu i stavljamo jednu pored druge. Koliko različitih redosleda boja možemo da dobijemo? Primer

More information

Linear Algebra and Matrices

Linear Algebra and Matrices Linear Algebra and Matrices 4 Overview In this chapter we studying true matrix operations, not element operations as was done in earlier chapters. Working with MAT- LAB functions should now be fairly routine.

More information

KVADRATNE INTERPOLACIJSKE METODE ZA JEDNODIMENZIONALNU BEZUVJETNU LOKALNU OPTIMIZACIJU 1

KVADRATNE INTERPOLACIJSKE METODE ZA JEDNODIMENZIONALNU BEZUVJETNU LOKALNU OPTIMIZACIJU 1 MAT KOL (Banja Luka) ISSN 0354 6969 (p), ISSN 1986 5228 (o) Vol. XXII (1)(2016), 5 19 http://www.imvibl.org/dmbl/dmbl.htm KVADRATNE INTERPOLACIJSKE METODE ZA JEDNODIMENZIONALNU BEZUVJETNU LOKALNU OPTIMIZACIJU

More information

Least squares regression

Least squares regression Curve Fitting Least squares regression Interpolation Two categories of curve fitting. 1. Linear least squares regression, determining the straight line that best fits data points. 2. Interpolation, determining

More information

AMSC/CMSC 466 Problem set 3

AMSC/CMSC 466 Problem set 3 AMSC/CMSC 466 Problem set 3 1. Problem 1 of KC, p180, parts (a), (b) and (c). Do part (a) by hand, with and without pivoting. Use MATLAB to check your answer. Use the command A\b to get the solution, and

More information

Examples and MatLab. Vector and Matrix Material. Matrix Addition R = A + B. Matrix Equality A = B. Matrix Multiplication R = A * B.

Examples and MatLab. Vector and Matrix Material. Matrix Addition R = A + B. Matrix Equality A = B. Matrix Multiplication R = A * B. Vector and Matrix Material Examples and MatLab Matrix = Rectangular array of numbers, complex numbers or functions If r rows & c columns, r*c elements, r*c is order of matrix. A is n * m matrix Square

More information

Vektori u ravnini i prostoru. Rudolf Scitovski, Ivan Vazler. 10. svibnja Uvod 1

Vektori u ravnini i prostoru. Rudolf Scitovski, Ivan Vazler. 10. svibnja Uvod 1 Ekonomski fakultet Sveučilište J. J. Strossmayera u Osijeku Vektori u ravnini i prostoru Rudolf Scitovski, Ivan Vazler 10. svibnja 2012. Sadržaj 1 Uvod 1 2 Operacije s vektorima 2 2.1 Zbrajanje vektora................................

More information

Matrix Arithmetic. j=1

Matrix Arithmetic. j=1 An m n matrix is an array A = Matrix Arithmetic a 11 a 12 a 1n a 21 a 22 a 2n a m1 a m2 a mn of real numbers a ij An m n matrix has m rows and n columns a ij is the entry in the i-th row and j-th column

More information

JUST THE MATHS UNIT NUMBER DIFFERENTIATION 3 (Elementary techniques of differentiation) A.J.Hobson

JUST THE MATHS UNIT NUMBER DIFFERENTIATION 3 (Elementary techniques of differentiation) A.J.Hobson JUST THE MATHS UNIT NUMBER 10.3 DIFFERENTIATION 3 (Elementary techniques of differentiation) by A.J.Hobson 10.3.1 Standard derivatives 10.3.2 Rules of differentiation 10.3.3 Exercises 10.3.4 Answers to

More information

Basic Linear Algebra in MATLAB

Basic Linear Algebra in MATLAB Basic Linear Algebra in MATLAB 9.29 Optional Lecture 2 In the last optional lecture we learned the the basic type in MATLAB is a matrix of double precision floating point numbers. You learned a number

More information

Matrix & Linear Algebra

Matrix & Linear Algebra Matrix & Linear Algebra Jamie Monogan University of Georgia For more information: http://monogan.myweb.uga.edu/teaching/mm/ Jamie Monogan (UGA) Matrix & Linear Algebra 1 / 84 Vectors Vectors Vector: A

More information

Linear Algebra Using MATLAB

Linear Algebra Using MATLAB Linear Algebra Using MATLAB MATH 5331 1 May 12, 2010 1 Selected material from the text Linear Algebra and Differential Equations Using MATLAB by Martin Golubitsky and Michael Dellnitz Contents 1 Preliminaries

More information

COLUMN VECTORS a=[1;2;3] b. a(1) = first.entry of a

COLUMN VECTORS a=[1;2;3] b. a(1) = first.entry of a Lecture 2 vectors and matrices ROW VECTORS Enter the following in SciLab: [1,2,3] scilab notation for row vectors [8]==8 a=[2 3 4] separate entries with spaces or commas b=[10,10,10] a+b, b-a add, subtract

More information

pretraživanje teksta Knuth-Morris-Pratt algoritam

pretraživanje teksta Knuth-Morris-Pratt algoritam pretraživanje teksta Knuth-Morris-Pratt algoritam Jelena Držaić Oblikovanje i analiza algoritama Mentor: Prof.dr.sc Saša Singer 18. siječnja 2016. 18. siječnja 2016. 1 / 48 Sadržaj 1 Uvod 2 Pretraživanje

More information

MATLAB BASICS. Instructor: Prof. Shahrouk Ahmadi. TA: Kartik Bulusu

MATLAB BASICS. Instructor: Prof. Shahrouk Ahmadi. TA: Kartik Bulusu MATLAB BASICS Instructor: Prof. Shahrouk Ahmadi 1. What are M-files TA: Kartik Bulusu M-files are files that contain a collection of MATLAB commands or are used to define new MATLAB functions. For the

More information

Položaj nultočaka polinoma

Položaj nultočaka polinoma Osječki matematički list 4 (204), 05-6 Položaj nultočaka polinoma Mandalena Pranjić Rajna Rajić Sažetak Prema Rolleovom teoremu, bilo koji segment čiji su krajevi međusobno različite realne nultočke polinoma

More information

LINEAR SYSTEMS, MATRICES, AND VECTORS

LINEAR SYSTEMS, MATRICES, AND VECTORS ELEMENTARY LINEAR ALGEBRA WORKBOOK CREATED BY SHANNON MARTIN MYERS LINEAR SYSTEMS, MATRICES, AND VECTORS Now that I ve been teaching Linear Algebra for a few years, I thought it would be great to integrate

More information

2D Plotting with Matlab

2D Plotting with Matlab GEEN 1300 Introduction to Engineering Computing Class Meeting #22 Monday, Nov. 9 th Engineering Computing and Problem Solving with Matlab 2-D plotting with Matlab Script files User-defined functions Matlab

More information

Nilpotentni operatori i matrice

Nilpotentni operatori i matrice Sveučilište J. J. Strossmayera u Osijeku Odjel za matematiku Sveučilišni preddiplomski studij matematike Nikolina Romić Nilpotentni operatori i matrice Završni rad Osijek, 2016. Sveučilište J. J. Strossmayera

More information

University of British Columbia Math 307, Final

University of British Columbia Math 307, Final 1 University of British Columbia Math 37, Final April 29, 214 12.-2.3pm Name: Student Number: Signature: Instructor: Instructions: 1. No notes, books or calculators are allowed. A MATLAB/Octave formula

More information

Solution of Linear systems

Solution of Linear systems Solution of Linear systems Direct Methods Indirect Methods -Elimination Methods -Inverse of a matrix -Cramer s Rule -LU Decomposition Iterative Methods 2 A x = y Works better for coefficient matrices with

More information

EEE161 Applied Electromagnetics Laboratory 1

EEE161 Applied Electromagnetics Laboratory 1 Dr. Milica Marković Applied Electromagnetics Laboratory page 1 EEE161 Applied Electromagnetics Laboratory 1 Instructor: Dr. Milica Marković Office: Riverside Hall 3028 Email: milica@csus.edu Web:http://gaia.ecs.csus.edu/

More information

Differential Equations DIRECT INTEGRATION. Graham S McDonald

Differential Equations DIRECT INTEGRATION. Graham S McDonald Differential Equations DIRECT INTEGRATION Graham S McDonald A Tutorial Module introducing ordinary differential equations and the method of direct integration Table of contents Begin Tutorial c 2004 g.s.mcdonald@salford.ac.uk

More information

Scilab Textbook Companion for Linear Algebra and Its Applications by D. C. Lay 1

Scilab Textbook Companion for Linear Algebra and Its Applications by D. C. Lay 1 Scilab Textbook Companion for Linear Algebra and Its Applications by D. C. Lay 1 Created by Animesh Biyani B.Tech (Pursuing) Electrical Engineering National Institute Of Technology, Karnataka College Teacher

More information

Prsten cijelih brojeva

Prsten cijelih brojeva SVEUČILIŠTE JOSIPA JURJA STROSSMAYERA U OSIJEKU ODJEL ZA MATEMATIKU Marijana Pravdić Prsten cijelih brojeva Diplomski rad Osijek, 2017. SVEUČILIŠTE JOSIPA JURJA STROSSMAYERA U OSIJEKU ODJEL ZA MATEMATIKU

More information

Homework 2. Matthew Jin. April 10, 2014

Homework 2. Matthew Jin. April 10, 2014 Homework Matthew Jin April 10, 014 1a) The relative error is given by ŷ y y, where ŷ represents the observed output value, and y represents the theoretical output value. In this case, the observed output

More information

Prepared by: M. S. KumarSwamy, TGT(Maths) Page

Prepared by: M. S. KumarSwamy, TGT(Maths) Page Prepared by: M. S. KumarSwamy, TGT(Maths) Page - 50 - CHAPTER 3: MATRICES QUICK REVISION (Important Concepts & Formulae) MARKS WEIGHTAGE 03 marks Matrix A matrix is an ordered rectangular array of numbers

More information

Companion. Jeffrey E. Jones

Companion. Jeffrey E. Jones MATLAB7 Companion 1O11OO1O1O1OOOO1O1OO1111O1O1OO 1O1O1OO1OO1O11OOO1O111O1O1O1O1 O11O1O1O11O1O1O1O1OO1O11O1O1O1 O1O1O1111O11O1O1OO1O1O1O1OOOOO O1111O1O1O1O1O1O1OO1OO1OO1OOO1 O1O11111O1O1O1O1O Jeffrey E.

More information

MATLAB crash course 1 / 27. MATLAB crash course. Cesar E. Tamayo Economics - Rutgers. September 27th, /27

MATLAB crash course 1 / 27. MATLAB crash course. Cesar E. Tamayo Economics - Rutgers. September 27th, /27 1/27 MATLAB crash course 1 / 27 MATLAB crash course Cesar E. Tamayo Economics - Rutgers September 27th, 2013 2/27 MATLAB crash course 2 / 27 Program Program I Interface: layout, menus, help, etc.. I Vectors

More information

Chapter 5 Roots of Equations: Bracketing Models. Gab-Byung Chae

Chapter 5 Roots of Equations: Bracketing Models. Gab-Byung Chae Chapter 5 Roots of Equations: Bracketing Models Gab-Byung Chae 2008 4 17 2 Chapter Objectives Studying Bracketing Methods Understanding what roots problems are and where they occur in engineering and science.

More information

Chapter I: Hands-on experience in SCILAB operations

Chapter I: Hands-on experience in SCILAB operations Chapter I: Hands-on experience in SCILAB operations Introduction to SCILAB SCILAB is a numerical mathematical equation solver which involves a powerful open computing environment for engineering and scientific

More information

1 Pogreške Vrste pogrešaka Pogreške zaokruživanja Pogreške nastale zbog nepreciznosti ulaznih podataka

1 Pogreške Vrste pogrešaka Pogreške zaokruživanja Pogreške nastale zbog nepreciznosti ulaznih podataka Sadržaj 1 Pogreške 1 1.1 Vrste pogrešaka...................... 1 1.1.1 Pogreške zaokruživanja.............. 1 1.1.2 Pogreške nastale zbog nepreciznosti ulaznih podataka....................... 2 1.1.3 Pogreška

More information

A matrix over a field F is a rectangular array of elements from F. The symbol

A matrix over a field F is a rectangular array of elements from F. The symbol Chapter MATRICES Matrix arithmetic A matrix over a field F is a rectangular array of elements from F The symbol M m n (F ) denotes the collection of all m n matrices over F Matrices will usually be denoted

More information

ELEMENTARY LINEAR ALGEBRA

ELEMENTARY LINEAR ALGEBRA ELEMENTARY LINEAR ALGEBRA K. R. MATTHEWS DEPARTMENT OF MATHEMATICS UNIVERSITY OF QUEENSLAND Second Online Version, December 1998 Comments to the author at krm@maths.uq.edu.au Contents 1 LINEAR EQUATIONS

More information

Chapter I. Linear Equations

Chapter I. Linear Equations Chapter I Linear Equations I Linear Equations I. Solving Linear Equations Prerequisites and Learning Goals From your work in previous courses, you should be able to Write a system of linear equations using

More information

NIPP. Implementing rules for metadata. Ivica Skender NSDI Working group for technical standards.

NIPP. Implementing rules for metadata. Ivica Skender NSDI Working group for technical standards. Implementing rules for metadata Ivica Skender NSDI Working group for technical standards ivica.skender@gisdata.com Content Working group for technical standards INSPIRE Metadata implementing rule Review

More information

Table 1 Principle Matlab operators and functions Name Description Page reference

Table 1 Principle Matlab operators and functions Name Description Page reference Matlab Index Table 1 summarises the Matlab supplied operators and functions to which we have referred. In most cases only a few of the options available to the individual functions have been fully utilised.

More information

7.1. Calculus of inverse functions. Text Section 7.1 Exercise:

7.1. Calculus of inverse functions. Text Section 7.1 Exercise: Contents 7. Inverse functions 1 7.1. Calculus of inverse functions 2 7.2. Derivatives of exponential function 4 7.3. Logarithmic function 6 7.4. Derivatives of logarithmic functions 7 7.5. Exponential

More information

DRUGI KOLOKVIJ ZADACI ZA VJEŽBU. 1. zadatak. Za rad s bazom podataka moja_baza koristimo naredbu:

DRUGI KOLOKVIJ ZADACI ZA VJEŽBU. 1. zadatak. Za rad s bazom podataka moja_baza koristimo naredbu: DRUGI KOLOKVIJ ZADACI ZA VJEŽBU 1. zadatak. Za rad s bazom podataka moja_baza koristimo naredbu: a. SELECT moja_baza b. ENTER moja_baza c. USE moja_baza d. OPEN moja_baza 2. zadatak. Koja od ovih naredbi

More information

SINTAKSNA I ALGORITAMSKA NOTACIJA

SINTAKSNA I ALGORITAMSKA NOTACIJA B-1 Prilog B SINTAKSNA I ALGORITAMSKA NOTACIJA B-2 B.1 Sintaksna notacija sa zagradama U osnovi svake sintaksne notacije nalaze se slede}i elementi: sintaksni pojam: leksi~ka konstrukcija koja se defini{e;

More information