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

3 ビュー (過去 30 日間)
Cian Thornberry
Cian Thornberry 2021 年 11 月 27 日
コメント済み: Cian Thornberry 2021 年 11 月 27 日
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 Center および File ExchangeSymbolic Math Toolbox についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by