필터 지우기
필터 지우기

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 CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by