Skip to content

Instantly share code, notes, and snippets.

@elvircrn
Created August 25, 2017 22:25
Show Gist options
  • Save elvircrn/1289f4eca73d1c7cf2d7d860e76902d7 to your computer and use it in GitHub Desktop.
Save elvircrn/1289f4eca73d1c7cf2d7d860e76902d7 to your computer and use it in GitHub Desktop.

Level 1

disp (a) -> display a

a.' -> transponovano

a' -> transponovano konjugovano

feval(X, Y, f);

meshgrid -> ovo ti treba za mesh

mesh -> s ovim crtas mesh

5 + 2 * %i;  // 5 + 2i

Poserem se na meshgrid

function plotme2(fun)
    xaxis = linspace(-4, 4, 70);
    deff('[z] = f(x, y)', 'z = ' + fun);
    [X, Y] = meshgrid(xaxis, xaxis);
    Z = feval(X(1,:), Y(:,1), f);
    disp(X);
    mesh(X, Y, Z);
endfunction

plotme2('1/ (x^2 + y^2)');

Level 2

Djeljenje

A \ B = inv(A) * B;

A / B = A * inv(B);

Leftdiv

A \ B;
inv(A) * B;
pinv(A) * B; // Penrose-Moore pseudo-inverse matrix

Korisne funkcije

cond -> // faktor uslovljenosti
spec -> // Singular valuei 
chol -> // Cholesky
rref -> // Kanonski oblik ustrojen po redovima

SVD Faktorizacija

[U, S, V] = svd(A);
S <- Singular values

Testmatrix

testmatrix({ 'magi',        'hilb' }, n);
                ^              ^
                |              |
            Magic square    Hilbert

Singular values via QR

alt text

Level 3

[y] = interp1(trainx, trainy, x, [method])
    * "linear"
    * "spline"

Runge one-liner

1 ./ (1 + (25 * (x .^ 2))); // where x is a vector

Level 4

P1 = poly(1:2:5,"x","c");  // koeficijenti
P2 = poly(1:3:10,"x","r"); // nule
roots(P1); // Nule polinoma
horner(P1, 5); // Evaluacija polinoma
F=chepol(4,"x"); // Chebishev 4. stepena varijable x

Level 5

derivat(P3);                                        // Izvod polinoma
pd = derivat(p);
[J,H] = numderivative(f, x, h, order, H_form);
[y] = intg(a, b, f);

Level 6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment