フィルターのクリア

Solve function not returning a zero

5 ビュー (過去 30 日間)
Ali Almakhmari
Ali Almakhmari 2023 年 5 月 8 日
移動済み: Torsten 2023 年 5 月 8 日
Hello guys. Sometimes, at certain x-values, the solve function doesn't report back a proper value so I get an error that says "Unable to perform assignment because the size of the left side is 1-by-2 and the size of the right side is 0-by-1.", which I totally expected and know about. The issue is that I want the yy values at those unsolvable points to be zero, but I keep getting the previously mentioned error. Any hints on how to do this?
syms y
a = 3;
b = 4;
c = 1;
d = 2;
g = 2.5;
x = -20:0.1:20;
yy = zeros(length(x),2);
eqn = (sqrt((x-a).^2 + (y-b).^2) - sqrt((x-c).^2 + (y-d).^2)).^2 == g.^2;
for ii = 1:length(x)
yy(ii,:) = double(solve(eqn(ii)));
end

採用された回答

Torsten
Torsten 2023 年 5 月 8 日
移動済み: Torsten 2023 年 5 月 8 日
syms x y
a = 3;
b = 4;
c = 1;
d = 2;
g = 2.5;
eqn = (sqrt((x-a).^2 + (y-b).^2) - sqrt((x-c).^2 + (y-d).^2)).^2 == g.^2;
sol = solve(eqn,y);
xnum = -20:0.1:20;
ynum = double(subs(sol,x,xnum));
figure(1)
plot(xnum,real([ynum(1,:);ynum(2,:)]))
figure(2)
plot(xnum,imag([ynum(1,:);ynum(2,:)]))

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCalculus についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by