help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

problem with function


From: Arnau Mir Torres
Subject: problem with function
Date: Mon, 14 Mar 2005 17:04:24 +0100
User-agent: Mozilla Thunderbird 0.8 (X11/20041012)

Hello.
I've defined the following function:

function y = serra(t)
global periode
if (t >= 0 && t <= periode/2)
       y = t./(-periode/2) +1;
else
       y = t./(-periode/2) +2;
endif
endfunction

If I do:

global periode = 200;
t=(0:10:200)';

and I try to print
serra(t), octave responses:

 2.00000
 1.90000
 1.80000
 1.70000
 1.60000
 1.50000
 1.40000
 1.30000
 1.20000
 1.10000
 1.00000
 0.90000
 0.80000
 0.70000
 0.60000
 0.50000
 0.40000
 0.30000
 0.20000
 0.10000
 0.00000

but I think this is wrong, because when t is between 0 and 100, serra(t) has a value between 1 and 0.
Moreover, if I do:

for i=1:length(t)
   y(i)=serra(t(i));
endfor

and next I do
y
octave responses the correct answer:
 1.00000
 0.90000
 0.80000
 0.70000
 0.60000
 0.50000
 0.40000
 0.30000
 0.20000
 0.10000
 0.00000
 0.90000
 0.80000
 0.70000
 0.60000
 0.50000
 0.40000
 0.30000
 0.20000
 0.10000
 0.00000
So, my question is:
why octave does this? Is this a bug?

Thanks,
Arnau.

--
Arnau Mir Torres
Director Departament Matemàtiques i Informàtica.
Universitat de les Illes Balearss.
Edifici A. Turmeda, Campus de la UIB.
Crta. de Valldemossa, km. 7,5.
07122 Palma de Mallorca.
Baleares.
Spain.
Phone: +34 971 172987
Fax: +34 971 173003
e-mail: address@hidden
web: http://dmi.uib.es/~arnau



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]