Problem with specific math function (x^2-1)/(x^2+1)[SOLVED]

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem with specific math function (x^2-1)/(x^2+1)[SOLVED]

koleygr
This post was updated on .
Hi, I am trying to plot the above function.

My code is:

x=0:0.05:5;
f=@(x) (x.*x-1)/(x.*x+1);
y=f(x)
%Here it prints just one value of y and that's the problem!!!
plot(x,y,'r')

The next is the same but with simpler function and it works
f=@(x) x.*x;
y=f(x)
%Here it works fine!!!
plot(x,y,'r')

So, I think it is a bug or something
(version=3.8.2 on debian)
Reply | Threaded
Open this post in threaded view
|

Re: Problem with specific math function (x^2-1)/(x^2+1)

koleygr
I had not subscribed on the mailing list...

I think it is ok now
Reply | Threaded
Open this post in threaded view
|

Re: Problem with specific math function (x^2-1)/(x^2+1) [SOLVED]

koleygr
I found I had to make the division like (x.*x-1)./(x.*x+1)

Solved

Thanks
Reply | Threaded
Open this post in threaded view
|

Re: Problem with specific math function (x^2-1)/(x^2+1)

nrjank
In reply to this post by koleygr
On Mon, May 22, 2017 at 1:49 PM, koleygr <[hidden email]> wrote:
I had not subscribed on the mailing list...

I think it is ok now

not sure if you meant the subscription or the function, but

f=@(x) (x.*x-1)/(x.*x+1);

should be

f=@(x) (x.*x-1)./(x.*x+1);

notice the ./ which will do elementwise division.



_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave