Solve function not returning a zero

3 vues (au cours des 30 derniers jours)
Ali Almakhmari
Ali Almakhmari le 8 Mai 2023
Déplacé(e) : Torsten le 8 Mai 2023
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

Réponse acceptée

Torsten
Torsten le 8 Mai 2023
Déplacé(e) : Torsten le 8 Mai 2023
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,:)]))

Plus de réponses (0)

Catégories

En savoir plus sur Mathematics and Optimization dans Help Center et File Exchange

Tags

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by