你如何在 matlab 中绘制这个特定的函数?

How do you plot this particular function in matlab?

我想在Matlab中画出这两个函数

g(x) = sin(x)/(1+x^2) 和
f(x) = (x^2)/(2-x)

但是我正在为此苦苦挣扎,这是我的代码

x=linspace(-5,5); 
y1= sin(x)/(1+x^2);
y2= x^2/(2-x);
plot(x,y1,x,y2)

每次我尝试 运行 时都会显示一个空图。

当您 运行 您的代码时,您会发现您收到以下错误:

Error using ^
Inputs must be a scalar and a square matrix.
To compute elementwise POWER, use POWER (.^) instead.

正如消息中非常明确指出的那样,您需要使用power (.^) to perform the element-wise operation rather than mpower (^). Additionally, you'll want to use rdivide (./) rather than mrdivide/)来执行逐元素除法。

y1 = sin(x) ./ (1+x.^2);
y2 = x.^2 ./ (2-x);

如果你想让每块地块都有自己的比例,你可以使用yyaxis

yyaxis left
plot(x, y1)
yyaxis right
plot(x, y2);