Main Content

refcurve

プロットへの参照曲線の追加

構文

refcurve(p)
refcurve
refcurve(ax,p)
hcurve = refcurve(...)

説明

refcurve(p) は、係数 p をもつ多項式参照曲線を現在の軸に追加します。pn+1 要素をもつベクトルの場合、曲線は以下のとおりです。

y = p(1)*x^n + p(2)*x^(n-1) + ... + p(n)*x + p(n+1)

入力引数のない refcurve は、x 軸に沿ってラインを追加します。

refcurve(ax,p) は、Axes オブジェクト ax で指定されたプロットの座標軸を使用します。詳細については、axes を参照してください。

hcurve = refcurve(...) は、前の構文におけるいずれかの入力引数の組み合わせを使用して、ハンドル hcurve を曲線に返します。

すべて折りたたむ

多項式トレンドをもつデータを生成します。

p = [1 -2 -1 0];
t = 0:0.1:3;
rng default  % For reproducibility
y = polyval(p,t) + 0.5*randn(size(t));

データをプロットし、refcurve を使用して、母集団平均関数を追加します。

plot(t,y,'ro')
h = refcurve(p);
h.Color = 'r';

Figure contains an axes object. The axes object contains 2 objects of type line. One or more of the lines displays its values using only markers

近似平均関数も追加します。

q = polyfit(t,y,3);
refcurve(q)
legend('Data','Population Mean','Fitted Mean', ...
    'Location','NW')

Figure contains an axes object. The axes object contains 3 objects of type line. One or more of the lines displays its values using only markers These objects represent Data, Population Mean, Fitted Mean.

関連する物理定数を導入します。

M = 0.145;      % Mass (kg)
R = 0.0366;     % Radius (m)
A = pi*R^2;     % Area (m^2)
rho = 1.2;      % Density of air (kg/m^3)
C = 0.5;        % Drag coefficient
D = rho*C*A/2;  % Drag proportional to the square of the speed
g = 9.8;        % Acceleration due to gravity (m/s^2)

各時間区間の加速度は一定であると推測し、速度の二乗に比例する、バットを引いて (ドラッグして) 打ったボールの軌跡をシミュレートします。

dt = 1e-2;      % Simulation time interval (s)
r0 = [0 1];     % Initial position (m)
s0 = 50;        % Initial speed (m/s)
alpha0 = 35;    % Initial angle (deg)
v0 = s0*[cosd(alpha0) sind(alpha0)]; % Initial velocity (m/s)

r = r0;
v = v0;
trajectory = r0;
while r(2) > 0
    a = [0 -g] - (D/M)*norm(v)*v;
    v = v + a*dt;
    r = r + v*dt + (1/2)*a*(dt^2);
    trajectory = [trajectory;r];
end

trajectory をプロットし、refcurve を使用してバットを引かずに (ドラッグしない) 打ったボールの放物型軌跡 (解析的に求める) を、この軌跡のプロットに追加します。

figure
plot(trajectory(:,1),trajectory(:,2),'m','LineWidth',2)
xlim([0,250])
h = refcurve([-g/(2*v0(1)^2),...
    (g*r0(1)/v0(1)^2) + (v0(2)/v0(1)),...
    (-g*r0(1)^2/(2*v0(1)^2)) - (v0(2)*r0(1)/v0(1)) + r0(2)]);
h.Color = 'c';
h.LineWidth = 2;
axis equal
ylim([0,50])
grid on
xlabel('Distance (m)')
ylabel('Height (m)')
title('{\bf Baseball Trajectories}')
legend('With Drag','Without Drag')

Figure contains an axes object. The axes object with title blank Baseball blank Trajectories, xlabel Distance (m), ylabel Height (m) contains 2 objects of type line. These objects represent With Drag, Without Drag.

バージョン履歴

R2006a より前に導入