help-octave
[Top][All Lists]
Advanced

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

Re: How to print this function?


From: Sergei Steshenko
Subject: Re: How to print this function?
Date: Tue, 22 May 2012 11:26:36 -0700 (PDT)





>________________________________
> From: lib1 <address@hidden>
>To: address@hidden 
>Sent: Tuesday, May 22, 2012 8:39 PM
>Subject: Re: How to print this function?
> 
>
>Thank you Max! 
>
>2012/5/22 Max Brister [via Octave] <[hidden email]>: 
>
>> On Tue, May 22, 2012 at 10:58 AM, lib1 <[hidden email]> wrote: 
>> 
>>> Hi, 
>>> 
>>> This is a beginner question, but can't seem to figure this out. 
>>> 
>>> Please consider: 
>>> 
>>>  t = [-1:0.1:1;] 
>>> 
>>> f = ( 1 + t ) / ( 1 - t); 
>>> 
>>> plot (t, f); 
>>> 
>>> 
>>> I'd like to see the behavior of f function regarding t values, but all I 
>>> get 
>>> is some point. 
>>> How should I do this? 
>> 
>> By default octave does matrix math. So, (1 + t) /  (1 - t) does matrix 
>> division resulting in a single scalar value. It looks like you really 
>> want to do element-wise division, this is achieved through adding a 
>> dot in front of the division operator like: 
>> f = (1 + t) ./ (1 - t); 
>> 
>> Max Brister 


Though not related to your original question, 0.1 may be a periodic fraction in 
your _binary_ CPU, so you better write


t = 0.1 * [-10:1:10];

.


See http://en.wikipedia.org/wiki/Repeating_decimal , 
http://www.cut-the-knot.org/blue/frac_conv.shtml , etc.

For starters:

"
octave:3> fprintf(stderr, "%.24f\n", 0.1);
0.100000000000000005551115
octave:4> fprintf(stderr, "%.24f\n", 0.01);
0.010000000000000000208167
octave:5> fprintf(stderr, "%.24f\n", 0.001);
0.001000000000000000020817
octave:6>
".

I.e. your code works by luck, not by design.


Regards,
  Sergei.


reply via email to

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