0
votes

While reading a tutorial on Octave I found the following line of code that produces a sin plot:

fplot (@sin, [-10, 10]);

I decided I wanted to plot tan instead of sin so I entered the following command:

fplot (@tan, [-10, 10]);

When I did this I got the following plot: enter image description here

Why did I get that graph instead of one of a tan function? How can I plot a tan function?

1
This problem is not reproducible in MATLAB (atleast in 2016a and 2016b) . MATLAB 2016a and 2016b give this: i.stack.imgur.com/89Lb9.png - Sardar Usama

1 Answers

1
votes

You are trying to plot tan from -10..10. This function goes to +/-inf (for example tan(pi/2)) so the autoscale tries to plot from -inf to inf...

Try setting the limits manually:

fplot (@tan, [-10, 10]);
set (gca, 'ylim', [-10 10])  

tan plot

or adapt your limits:

fplot (@tan, [-0.9 * pi/2, 0.9 * pi/2]);