|
From: | Tasos Papastylianou |
Subject: | Re: Variables.... |
Date: | Tue, 12 Feb 2013 03:42:41 -0800 (PST) |
Γειά σου Τάσο!
The short answer is, yes. Any variable needs to be declared before you can use it.
To answer your question on why the matrix is not a 3 x 3 matrix in your scenario:
When you do global a
, you force a variable a
to appear on your base workspace, but it is given the value []
(i.e. an empty set). Note that this is not the same as zero!
Therefore, adding 2
to the empty set (i.e. [] + 2
) still returns an empty set (since you're adding '2' to all elements of the empty set, which hasn't got any). This is different to saying 0 + 2
(i.e. [0] + 2
) because in this cause you're adding '2' to all elements of the set; this time the set contains one element, which happens to be zero, so your result will not be an empty set now.
In your specific example:
octave-cli:1> a = [] a = [](0x0) octave-cli:2> X = [(a+2) 3 4; 5 (a-4) 8; 3 2 (a-1)] X = 3 4 5 8 3 2 octave-cli:3> a = 0; octave-cli:4> X = [(a+2) 3 4; 5 (a-4) 8; 3 2 (a-1)] X = 2 3 4 5 -4 8 3 2 -1Hope this helps :)
[Prev in Thread] | Current Thread | [Next in Thread] |