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

답변 (1개)

John D'Errico
John D'Errico 2022년 12월 8일
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

Lova
Lova 2022년 12월 8일
Lova
Lova 2022년 12월 8일
thats my try but i can only plot the first function
Torsten
Torsten 2022년 12월 8일
편집: Torsten 2022년 12월 8일
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.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Line Plots에 대해 자세히 알아보기

질문:

2022년 12월 8일

편집:

2022년 12월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by