Solve function not returning a zero
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
0 commentaires
Réponse acceptée
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,:)]))
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Mathematics and Optimization dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!