如何在 Matlab 中绘制二次函数(具有不同比例的轴)

How to plot a quadratic function in Matlab (with differently scaled axes)

我正在尝试创建一个具有 2 个不同比例轴的根函数图,假设 x 轴从 0 到 1.2,步长为 0.1,y 轴从 0 到 1.4,步长为 0.2 (一个功能,2 个不同比例的轴)。我想我的缩放是正确的,如果有更好的编程方法请指正我。

这是我的代码:

x = linspace(0,1.2);
y = 0.5 + (0.9 * (x.^2 - 0.0432)).^(1/2);

% here I need the negative part as well: 0.5 - [...] as follows:
% y2 = 0.5 - (0.9 * (x.^2 - 0.0432)).^(1/2); 
% How can I create this function and plot it?

plot(x,y)
axis([0 1.2 0 1.4])
set(gca,'xTick',0:0.1:1.2)
set(gca,'yTick',0:0.2:1.4)

grid on

我有函数的上半部分,但没有下半部分(负数,见上面代码中的注释)。它是如何创建的?或者,如果那不可能,我如何根据不同定义的 'subgraphs' 创建图表?该域需要以某种方式限制为 x >= 0.206.

你很接近!我会做以下事情。请参阅下面代码中的注释:

n = 1000;                % number of points. More points, smoother 
                         % looking piecewise linear approx. of curve

x0 = sqrt(.0432)+eps;    % Choose smallest xvalue to be at or epsilon to the right
                         % of the apex of the parabola

x = linspace(x0, 1.2, n)';   %'  transpose so x is a column vector (more convenient)
y_pos = 0.5 + (0.9 * (x.^2 - 0.0432)).^(1/2); % positive branch of parabola
y_neg = 0.5 - (0.9 * (x.^2 - 0.0432)).^(1/2); % negative branch of parabola

plot(x,[y_pos, y_neg],'blue')  % we´re graphing two series but use 'blue'
                               % for both so it looks like one series!
axis([0 1.2 0 1.4])
set(gca,'xTick',0:0.1:1.2)
set(gca,'yTick',0:0.2:1.4)

grid on