How can I use the solve command in Matlab to find the intersection of two equations?
4 views (last 30 days)
Show older comments
eqn1 = x^2 + y^2 ==9;
eqn2 = 2*x + 3*y == 4;
S = solve(eqn2==eqn1)
0 Comments
Answers (1)
DGM
on 27 Nov 2021
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)
sy = double(S.y)
% 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
See Also
Categories
Find more on Calculus in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!