Borrar filtros
Borrar filtros

Solve function not returning a zero

5 visualizaciones (últimos 30 días)
Ali Almakhmari
Ali Almakhmari el 8 de Mayo de 2023
Movida: Torsten el 8 de Mayo de 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

Respuesta aceptada

Torsten
Torsten el 8 de Mayo de 2023
Movida: Torsten el 8 de Mayo de 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,:)]))

Más respuestas (0)

Etiquetas

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by