plot two implicit functions in one figure

How can i plot these two functions into the same figure, ive tried to read the tips but I cannot do it. And also i have to find the intersection after ive plotted them.
(2*x.^2)+(2*y.^2)-5) and x*y-1

Answers (1)

Show what you have tried. If nothing, why not? First, apparently you know what an implicit function is. So have you tried using fimplicit? Next, a piece you are missing is the hold command.
help hold
HOLD Hold current graph HOLD ON holds the current plot and all axis properties, including the current color and linestyle, so that subsequent graphing commands add to the existing graph without resetting the color and linestyle. HOLD OFF returns to the default mode whereby PLOT commands erase the previous plots and reset all axis properties before drawing new plots. HOLD, by itself, toggles the hold state. HOLD does not affect axis autoranging properties. HOLD ALL is the same as HOLD ON. This syntax will be removed in a future release. Use HOLD ON instead. HOLD(AX,...) applies the command to the Axes object AX. Algorithm note: HOLD ON sets the NextPlot property of the current figure and axes to "add". HOLD OFF sets the NextPlot property of the current axes to "replace". See also ISHOLD, NEWPLOT, FIGURE, AXES. Documentation for hold doc hold
But then you need to solve for the intersection. Would not solve do that? Or fsolve, if you want a numerical solution that does not rely on symbolic tools?

4 Comments

thats my try but i can only plot the first function
fimplicit(@(x,y)(2*x.^2)+(2*y.^2)-5)
hold on
fimplicit(@(x,y)x.*y-1)
Ok then good. So you did not need to use linspace at all.
fimplicit was all you need, sandwiched between two calls to fimplicit.
fimplicit(@(x,y) 2*x.^2 + 2*y.^2 - 5) % this is the equation of a circle
hold on
fimplicit( @(x,y) x.*y - 1) % the equation of a hyperbola
axis equal
The axis equal command insures the x and y axes have the same spacing. Otherwise, the circle will look like an ellipse.
But now you need to solve for the solutions. You can use solve or fsolve. But remember that solve will require you make the variables symbolic. And fsolve will force you to convert it into a function with one vector argument. For example, to use fsolve, you might write this piece as:
f1 = @(xy) 2*xy(1).^2 + 2*xy(2).^2 - 5
But finally, then you need to remember that fsolve will find only one solution at a time, wheras solve should find all 4 solutions.

Sign in to comment.

Categories

Asked:

on 8 Dec 2022

Edited:

on 8 Dec 2022

Community Treasure Hunt

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

Start Hunting!