User Tools

Site Tools


software:scilab:linear-algebra

Linear algebra

Vector

To define a column vector:

v = [1; 2; 3]

To define a row vector, two syntaxes are possible:

v = [1 2 3]
v = [1, 2, 3]

Matrix

To define a matrix:

M = [1 2 3; 4 5 6; 7 8 9]

$$ \begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \\ \end{bmatrix} $$

Get element from vector/matrix

Get element from a vector v:

  • to get element in the <i>-position:
    v(<i>)

Get element from a matrix M:

  • to get the element in the <i>-row and <j>-column:
    M(<i>,<j>)
  • to get the whole <i>-row:
    M(<i>,:)
  • to get the whole <j>-column:
    M(:,<j>)
  • to get the whole <j>-<k>-columns:
    M(:,[<j>,<k>])
  • to get the whole <i>-<k>-rows:
    M([<i>,<k>],:)

Data structure

The struct() method allows to save data in the form <field>, <value>.

Create data structure with a loop

g = list("g1", "g2", "g3")
p = struct()

for i = g
    p(i) = i
end

fn = fieldnames(p)
for j = fn'
    disp(p(j))
end
software/scilab/linear-algebra.txt · Last modified: 2020/07/28 08:02 by tormec