I just started learning Matlab again after not having used it in months, and got some odd results -
Trying to plot tan(x), from -pi/2 to pi/2 -
I ended up getting something that has a negative spike at 0 and positive spike at 100. Certainly doesn't look like tan(x) to me.
X = (-pi/2):pi/100:(pi/2);
for i = 1:length(X)
Y(i) = tan(X(i));
I'm sure it's something simple, but it's been an hour already...
Ah! Ok. It seems like the big dynamic range threw Matlab off somehow. Adding clamping works.
You don't need that for loop, tan() and many other functions accept/output arrays:
Y = tan(X);
Also, you need to plot against an independent variable:
It looks sharp because pi/100 isn't a small enough step size, try .01 lower