1 / 6

Matlab

Matlab. Generiranje podatkov. Matrike. Osnovne matrike eye (n) in eye (m, n) : identična matrika zeros (n) in zeros (m, n) : same ničle ones (n) in ones (m, n) : same enke rand (n) in rand (m,n) : matrika z naključnimi števili z [0,1)

kioko
Download Presentation

Matlab

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 Generiranje podatkov

  2. Matrike • Osnovne matrike • eye(n) in eye(m, n) : identična matrika • zeros(n) in zeros(m, n) : same ničle • ones(n) in ones(m, n) : same enke • rand(n) in rand(m,n) : matrika z naključnimi števili z [0,1) • randi(doKam, n) in randi(doKam, n, m) : matrika z naključnimi celimi števili [1, doKam] • Posebne matrike • magic(n) : magični kvadrat • hilb(n) : hilbertova matrika (1, ½, 1/3 …) • …

  3. Generiranje vektorjev • X = [od : korak : do] • Vsa soda dvomestna števila • X = [10 : 2 : 99] • Števila od 10 do 0 • X = [10 : -1 : 0] • X = [od : do] • Isto kot x = [od:1:do] • linspace(od, do, koliko) • x = linspace(-pi, pi, 10) % 10 vrednosti od –Pi do Pi • Isto kot x = [-pi : 2*pi/9 : pi] • Matrika 10 x 10, ki ima na diagonali 1, 2, …, 10 • diagonala = [1:10] • Matr = diag(diagonala) • Vektor 5 metov kocke • metiKocke = randi(6,1,5)

  4. Operacije na vektorjih • Vektor 10 enakih metov kocke • enakiMeti = randi(6) * ones(1,10) • število op vektor • Npr. 5 + [3, 4, 5, 2] • Operacija se izvede po komponentah • [1, 2, 3, 1] + [3, 4, 5, 2] • [4, 6, 8, 3] • [1, 2, 3, 1] * [3, 4, 5, 2] • Napaka! • [1, 2, 3, 1] .* [3, 4, 5, 2] • Po komponentah • [3, 8, 15, 2] • Podobno pri matrikah: .op : operacija op se izvaja po komponentah

  5. Funkcije • Matematične funkcije nad vektorji in matrikami: • sin, cos, … • Izvajajo se po komponentah • Tabeliraj funcijo sinus na intervalu [-pi, pi] s korakom pi/4 • x = [-pi : pi/4 : pi] • vrednostiX = sin(x)

  6. Še nekaj uporabnih funkcij • size(M) • dimenzija matrike • Rezultat je vektor • Dolžina vektorja • dimV = size(v) • velV = dimV(2) • Ali gre v enem koraku: • size(v)(2) • MATLAB "protestira" • max(size(v)) • sum(x) • če je x vektor (ali vektor stolpec) : vsota elementov • Če je x matrika: dobimo vektor vsot stolpcev • prod(x) • dot(x, y) : x . y – skalarni produkt

More Related