// #1
t=-100:0.1:100;
t=t';
P=4;
for i=t(1:2001)
Wm(i)=%e^(2*%pi*%i*i)*%e^((-1)*i^2/(2*P^2));
end,
// !--error 10
// inconsistent multiplication
// //////////////////////////////////////////
// #2
t=-100:0.1:100;
// t=t';
P=4;
for i=t(1:2001)
Wm(i)=%e^(2*%pi*%i*i)*%e^((-1)*i^2/(2*P^2));
end,
// !--error 21
// invalid index
// //////////////////////////////////////////
// #3
t=1:0.1:100;
// t=t';
P=4;
for i=t(1:991)
Wm(i)=%e^(2*%pi*%i*i)*%e^((-1)*i^2/(2*P^2));
end,
// positiv index - this works (!)
// /////////////////////////////////////////
// #4
P=4;
Wm=%e^(2*%pi*%i*(-50))*%e^((-1)*(i)^2/(2*P^2))
// one negative argument - this works too (!)
// /////////////////////////////////////////
// #5
t=-100:0.1:100;
t=t';
P=4;
for i=t(1:2001)
Wm(i)=%e^(2*%pi*%i*(i))*%e^((-1)*(i)^2/(2*P^2));
end,
// !--error 10
// inconsistent multiplication
// (in spite of using parentheses)
loop ranges have to be row vectors. You're looping on a single
column vector value of i.
> Wm(i)
auto-growing vectors is inefficient and potential source of programming
mistakes
=%e^(2*%pi*%i*i)*%e^((-1)*i^2/(2*P^2));
> end,
> // !--error 10
> // inconsistent multiplication
vector*vector is inconsistent as a matrix product
> // #2
> t=-100:0.1:100;
> for i=t(1:2001)
> Wm(i)
Wm(-100) is illegal
> // #3
> t=1:0.1:100;
>
> // positiv index - this works (!)
but assigns ten times a value to each Wm(i) (the last counts)
> Wm=%e^(2*%pi*%i*(-50))*%e^((-1)*(i)^2/(2*P^2))
>
> // one negative argument - this works too (!)
scalar expression, nothing to do with sign
> // #5
same as #1 & #2
Thank You very much for the answers.
> > for i=t(1:2001)
>
> loop ranges have to be row vectors. You're looping on a single
> column vector value of i.
Unfortunetely I don't understand this, but maybe because of that
> vector*vector is inconsistent as a matrix product
I tried the line t=t'; ...
(I will put a second reply-email concerning problems of understanding
the philosophy of vectors in scilab.)
> > Wm(i)
>
> auto-growing vectors is inefficient and potential source of
> programming mistakes
Usually I try to avoid such things (and loops at all) [but sometimes I
have no other ideas].
Here, it was just a try, because the following code didn't work.
// first try
x=-1000:0.1:1000;
// deff('[s1,s2,...]=newfunction(e1,e2,....)',text [,opt])
deff('[Wm]=y(t,P)','Wm=%e^(2*%pi*%i*t)*%e^(-t^2/(2*P^2))')
P=4;
y=Wm(x,P);
plot(real(y))
plot(imag(y))
// ////////////////////////////////////////////////
Later I found a solution...
But until now I don't understand the problems before.
// late solution
x=-40:0.1:40;
P=4;
// Pchar = sprintf("%d",P);
Wm=exp((2*%pi*%i*x)+((-1)*x^2/(2*P^2)));
//xset("window",0),
//xbasc(),
//// xsetech(arect=[l, r, o, u]),
//xsetech(arect=[0.05,0.05,0.09,0.04]),
//xtitle('Morletwavelet omega_0=1; sigma='+Pchar+'')
//plot2d(x,real(Wm),-1,frameflag=6)
//plot2d(x,imag(Wm),1,frameflag=8)
//plot2d(x,abs(Wm),0,frameflag=8)
>
> > // #2
> > t=-100:0.1:100;
> > for i=t(1:2001)
> > Wm(i)
>
> Wm(-100) is illegal
But why?
>
> > // #3
> > t=1:0.1:100;
> >
> > // positiv index - this works (!)
>
> but assigns ten times a value to each Wm(i) (the last counts)
This I don't understand.
>
> > Wm=%e^(2*%pi*%i*(-50))*%e^((-1)*(i)^2/(2*P^2))
> >
> > // one negative argument - this works too (!)
>
> scalar expression, nothing to do with sign
Isn't every step in the loop in #2 and #3 a scalar expression too?
(Isn't i in every step a scalar? Because t(1)=-100, ..., t(2001)=100 in
#2, isn't it?)
And why #2 works for positive arguments (which is #3)?
>
> > // #5
>
> same as #1 & #2
Of course, but You see, that I don't understand the problem in #2 in
comparision to #3 and #4 at all.
I think, it's really a problem, to understand scilab's work with (row-
and column-) vectors and I didn't find neither in the manual nor in the
internet a comprensive explanation.
Try:
// 1.
x=1:2000;
size(x)
length(x)
x(345)
// 2.
x=1:2000;
x=x';
size(x)
length(x)
x(345)
// 3.
for i=1:length(x) // for i=1:2000
x(i)=i;
end
size(x)
length(x)
x(345)
I think column-vectors and row-vectors are different things and should
be distinguished from each other concerning multiplication of matrizes.
But it's really not nice that in example 3 there You get another vector
than in example 1 and You can find out the differenze only by using the
size-command. (It seems to me, that length and index are somehow
intuitional.)
> But it's really not nice that in example 3 there You get another vector
> than in example 1 and You can find out the differenze only by using the
> size-command. (It seems to me, that length and index are somehow
> intuitional.)
You are not creating a new vector in Example 3. You are assigning values
to an existing vector created in Example 2. If you keep track of
transposition, it is not difficult to know whether a vector is row or
column.
Shiro Ogawa
>
>> Wm(-100) is illegal
>
> But why?
>> > // positiv index - this works (!)
>>
>> but assigns ten times a value to each Wm(i) (the last counts)
>
> This I don't understand.
You should perhaps look at "help insertion".
I perfectly agree that scilab documentation is awful in this respect. It
took me a long lookup to realize that basic explanations about matrix
indexing are not reported in places a newbie could think of. Though for me
everything is self evident after long practice, there is nothing usable
under anything like
apropos vector
apropos matrix
apropos index
apropos range
etc.
Not even to say, I wasn't able to find a mention about $.
Enrico
Thanks for the answer!
> mey.wer wrote:
> > scilab: vectors as 1xn or nx1 matrices
> >
> >
> > I think, it's really a problem, to understand scilab's work with
(row-
> > and column-) vectors and I didn't find neither in the manual nor in
the
> > internet a comprensive explanation.
> >
> >
> > Try:
> >
> >
> > // 1.
> > x=1:2000;
> > size(x)
> > length(x)
> > x(345)
> This is by the definition of : operator, a row vector.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^ ^^^^^^^^^^
THIS is really an interisting and important fact. (I just wonder
wherefrom You know this definition.)
> >
> >
> > // 2.
> > x=1:2000;
> > x=x';
> > size(x)
> > length(x)
> > x(345)
> You get a column vector by transposition (').
Of course.
> >
> > // 3.
> > for i=1:length(x) // for i=1:2000
> > x(i)=i;
> > end
> > size(x)
> > length(x)
> > x(345)
> You still get a column vector because x is defined as a column vector
at //2.
>
That's true. But the problem is deeper:
try this (y=|=x) (or again // 3. starting with ' clear x ' )
// 4.
for i=1:2000
y(i)=i;
end
size(y)
length(y)
y(345)
-->vc(3)=1
vc =
! 0. !
! 0. !
! 1. !
-->vr(1,3)=1
vr =
! 0. 0. 1. !
That shows, that x(i) is read by scilab as x(i,1). Thus for empty x You
will get a column vector (for i>1).
> >
> > I think column-vectors and row-vectors are different things and
should
> > be distinguished from each other concerning multiplication of
matrizes.
> Yes it is. Do you have an example that it is not?
That wasn't the question. The problem is (for me) that it isn't easy to
recognize in scilab to which sort a vector is belonging.
The "length" command works for both in the same way.
It is possible to extract or insert a value for both in the same way:
-->vr=[1 0 2 0 1]
vr =
! 1. 0. 2. 0. 1. !
-->vz=[1; 0; 2; 0; 1]
vz =
! 1. !
! 0. !
! 2. !
! 0. !
! 1. !
-->vr(3) // instead of vr(1,3)
ans =
2.
-->vr(3)=0 // instead of vr(1,3)=0
vr =
! 1. 0. 0. 0. 1. !
-->vz(3) // instead of vr(3,1)
ans =
2.
-->vz(3)=0 // instead of vr(3,1)=0
vz =
! 1. !
! 0. !
! 0. !
! 0. !
! 1. !
But the following is not possible:
-->vz.*vr
!--error 9999
inconsistent element-wise operation
Only
-->vz.*vr'
works (and of course (the completely different things)
-->vz*vr
and
-->vr*vz
)
I think the ambivalence of length(x) and x(i) is not nice!
> > (It seems to me, that length and index are somehow intuitional.)
And these problems are difficult to find out and to understand using
scilab help, because it's (nearly ?) impossible to find the
"definition" of ':' and 'x(i)' .
> Shiro Ogawa
> >
maybe reading in advance the help pages for
length
size
colon
assignation
extraction
matrices
could help.