How can I use the solve command in Matlab to find the intersection of two equations?

조회 수: 11 (최근 30일)
eqn1 = x^2 + y^2 ==9;
eqn2 = 2*x + 3*y == 4;
S = solve(eqn2==eqn1)

답변 (1개)

DGM
DGM 2021년 11월 27일
Something like this:
% solve system of equations
syms x y
eqn1 = x^2 + y^2 == 9;
eqn2 = 2*x + 3*y == 4;
S = solve([eqn2 eqn1],[x y]);
sx = double(S.x)
sx = 2×1
2.9346 -1.7038
sy = double(S.y)
sy = 2×1
-0.6231 2.4692
% just plot things numerically and see if the solutions make sense
N = 50;
x = linspace(-4,4,N);
y = x.';
surf(x,y,sqrt(x.^2+y.^2),'facealpha',0.8); hold on % a circle
surf(x,y,3*ones(N,N),'facealpha',0.8) % with radius 3
plot3(x,(4-2*x)/3,3*ones(1,N)) % intersects with a diagonal line
plot3(sx,sy,[3 3],'o','linewidth',2) % mark calculated solution points
colormap(parula)
shading flat

카테고리

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