简体   繁体   中英

MATLAB Not properly plotting graph

It seems that my MATLAB has some sort of trouble plotting anything that is over tan(x). For example, trying to plat (tan(x) + sin(x))/(2*tan(x)):

clc
clear all

x = 0:0.1:pi;

y1 = cos(x/2).^2;
subplot(1,2,1);
plot(x, y1);

y2 = (tan(x) + sin(x))/(2*tan(x));
subplot(1,2,2);
plot(x, y2);

I've tried putting it on it's own plot as well, but all I seem to get is a blank graph, but the axes are all lined up for the range I've set. The only thing that has made anything appear is removing the tan(x) on the bottom.

You should use the element-wise division operator ./ :

y2 = (tan(x) + sin(x))./(2*tan(x));

Indeed with a = (tan(x) + sin(x)) and b = (2*tan(x)) , what you wrote is:

y2 = a / b;

which is matrix division, y2 = a * pinv(b) , a scalar number in this case.

NB: As b cannot be inverted, matlab uses pseudo-inverse pinv

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