Solve two equations simultaneously

15 vues (au cours des 30 derniers jours)
ASHIK A S
ASHIK A S le 13 Avr 2018
Commenté : Star Strider le 13 Avr 2018
I have two equations that need to be solved simultaneously. The two equations are defined in 2D (using 2 variables spread in 2D using meshgrid function). So the best way I thought to solve these equations was to plot the two surfaces and find the intersection of the two surfaces. The intersection of the surfaces should be the solution of the surfaces.
I proceed in this way but the result is not the same as intended.
Is there a better way of solving it?? Thanks in advance

Réponses (2)

Star Strider
Star Strider le 13 Avr 2018
I am guessing here. I would subtract the surfaces, then you the contour (link) function to plot them. Specify the intersection as the [0 0] contour, then return that contour as the ‘C’ output. That should give you the (x,y) coordinates of the intersection.
For example:
[X,Y] = meshgrid( ... );
Eq1 = @(x,y) ...;
Eq2 = @(x,y) ...;
EqDif = Eq1(X,Y) - Eq2(X,Y);
figure
C = contour(EqDif, [0 0]);
See the documentation on Contour Properties (link) and specifically on ContourMatrix (link) for a detailed description.
  3 commentaires
John D'Errico
John D'Errico le 13 Avr 2018
Subtracting the surfaces does not find where both surfaces are simultaneously zero. It finds where the surfaces intersect. If the goal is to solve simultaneous equations, you need to use tools like fsolve.
Star Strider
Star Strider le 13 Avr 2018
My pleasure.
My interpretation of ‘solving two equations simultaneously’ is to solve for the points they have in common, so subtracting them and solving for the intersection would work.
If you want to do something other than that, please describe it.

Connectez-vous pour commenter.


John D'Errico
John D'Errico le 13 Avr 2018
NO. NO. NO. It is NOT true that the intersection of two surfaces is the same as solving two equations simultaneously!!!!!!!!!
Consider two functions, F(x,y), G(x,y). You can find the intersection of two surfaces by looking for solutions of
F(x,y) - G(x,y) = 0
The solution locus will be some possibly curved path in the (x,y) plane.
But that is NOT the simultaneous solution of two equations, thus
F(x,y) = 0
G(X,Y) = 0
TOTALLY different here. The solution here can be gained from a tool like fsolve, or solve, or vpasolve.
You can use a graphical solution too, thus overlay the contour plots of the two functions, specifically the zero level contour. So intersections of the curves in those two contour plots will be an APPROXIMATE solution to the system of two equations.

Community Treasure Hunt

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

Start Hunting!

Translated by