MATLAB 未正确绘制图形
MATLAB Not properly plotting graph
我的 MATLAB 似乎在绘制超过 tan(x) 的任何东西时遇到了一些问题。例如,尝试 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);
我也试过把它放在它自己的图上,但我似乎得到的只是一张空白图表,但轴都按照我设置的范围排列。唯一使任何东西出现的是移除底部的 tan(x)。
您应该使用逐元素除法运算符 ./
:
y2 = (tan(x) + sin(x))./(2*tan(x));
的确有一个=(tan(x) + sin(x))
和b = (2*tan(x))
,你写的是:
y2 = a / b;
这是矩阵除法,y2 = a * pinv(b)
,在这种情况下是标量。
NB:由于b
不能求逆,matlab使用伪逆pinv
我的 MATLAB 似乎在绘制超过 tan(x) 的任何东西时遇到了一些问题。例如,尝试 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);
我也试过把它放在它自己的图上,但我似乎得到的只是一张空白图表,但轴都按照我设置的范围排列。唯一使任何东西出现的是移除底部的 tan(x)。
您应该使用逐元素除法运算符 ./
:
y2 = (tan(x) + sin(x))./(2*tan(x));
的确有一个=(tan(x) + sin(x))
和b = (2*tan(x))
,你写的是:
y2 = a / b;
这是矩阵除法,y2 = a * pinv(b)
,在这种情况下是标量。
NB:由于b
不能求逆,matlab使用伪逆pinv