-1

私は一連の算術演算を行って直線方程式を決定し、それを でプロットしていezplotます。aしかし、またはの場合に悪いことが起こりb = 0ます。0( のように5*x+0*y-1=0)を含む直線の方程式を保存したいのですが、y消えてしまいます。別の回避策を見つけてください。


ここで私のコードの例を 編集します。

syms x y
hold on
for i = -1:0.5:1
    for j = -1:0.5:1
        ezplot(i*x+j*y+1, [0,10,0,10])
        pause
    end
end  

aまたはの場合は手動で線を引くことができますb = 0が、より一般的なアプローチが必要です。

4

1 に答える 1

0

私はまだあなたの質問を理解していませんが、あなたの例を実行すると、3回目の繰り返しで次のエラーが発生します:

Figure 使用エラー
単一入力は既存の Figure ハンドルまたは
1 ~ 2147483646 のスカラー整数で なければなりません

ezplot>determineAxes のエラー (563 行目)
figure(fig);

ezplot>ezplot1 のエラー (449 行目)
cax = determineAxes(fig);

ezplot のエラー (145 行目)
[hp, cax] = ezplot1(cax, f{1}, vars, labels,
args{:});

sym/ezplot のエラー (72 行目)
h = ezplot(fhandle(f),[y(1) y(2)],[y(3) y(4)]);

minimal_example のエラー (7 行目)
ezplot(i*x+j*y+1, [0,10,0,10])

(次回お尋ねの際は、この種の情報を含めてください)。
何が起こるかというと、コード内iまたはj質問内のいずれかまたはa乗算されている場合、入力引数が多すぎます。それらの 1 つが Figure ハンドルとして解釈されるため、評価を続行できません (ハンドルを持つ Figure がないため、すべての Figure はハンドルとして整数値を持つため、エラーが発生します)。 次のコードは、Figure ハンドルを に提供することで、これを軽減します。また、質問の命名法に対応するように とを変更しました。bxy00
ezplotijab

syms x y

% define a figure and return the handle, f1
f1=figure;

% after initializing the figure, set hold on
hold on

for a = -1:0.5:1
    for b = -1:0.5:1
        % pass the figure handle, f1, to ezplot:
        ezplot(a*x+b*y+1, [0,10,0,10],f1)
        pause
    end
end

これで、プロット内のすべての行が取得されます。

編集

a=0またはの場合、 にb=0渡される前に方程式が評価されるため、予期しない結果が生じる可能性がありますezplot。したがって、それ0*yは評価から消えます。0を使用する代わりに、浮動小数点の相対精度epsを使用して、この動作をバイパスできます。

syms x y

% define a figure and return the handle, f1
f1=figure;

% after initializing the figure, set hold on
hold on

for a = -1:0.5:1
    for b = -1:0.5:1
        % pass the figure handle, f1, to ezplot:
        % add eps to a and b so that the will be as close to zero
        %    as possible but not truly zero
        ezplot((a+eps)*x+(b+eps)*y+1, [0,10,0,10],f1);
        pause
    end
end
于 2013-09-26T18:26:53.403 に答える