简体   繁体   中英

Octave — Plotting a tan function

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: 在此处输入图片说明

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

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])  

棕褐色的情节

or adapt your limits:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM