1

In this way, the x==y+n straight line and the x ^ 2/a ^ 2+y ^ 2/b ^ 2==1 elliptic image can be drawn to the same coordinate system.

For example:

x^2/16 + y^2/9 == 1, x == 2 y + 1

Specific to the above ellipse and straight line

ClearAll["`*"]
eqns = {x^2/16 + y^2/9 == 1, x == 2 y + 1};
line = eqns[[2]]
ell = eqns[[1]]

pts = SolveValues[{line, ell}, {x, y}]; normalized = First[ell] - Last[ell]; (ass=ResourceFunction["EllipseProperties"][ell,{x,y}]; params={a->ass["SemimajorAxisLength"],b->ass["SemiminorAxisLength"]}) params = {a -> Sqrt[Denominator[Coefficient[normalized, x^2]]], b -> Sqrt[Denominator[Coefficient[normalized, y^2]]]} glin = line[[2]] /. params gell = b {-1, 1} Sqrt[1 - x^2/a^2] /. params; gpts = pts /. params; (Plot[{{glin,gell}},{x,-a,a}/.
params,Epilog->{Red,PointSize[0.02],Point[gpts]}]
)

ParametricPlot[{glin, y}, {y, -b - 0.5, b + 0.5} /. params, AxesLabel -> {x, y}]

The above code does not draw an ellipse and a straight line in the same coordinate system

1. This is how to draw a single line, but the system will give an error prompt when replacing the value of b:

ParametricPlot::plln: Limiting value -0.5-b in {y,-0.5-b,0.5 +b} is not a machine-sized real number.

Reference resources: An answer by Daniel Huber

ParametricPlot[{glin, y}, {y, -b - 0.5, b + 0.5},
  AxesLabel -> {x, y}] /. params

The function of line range expressed by b is that the range of line y value is consistent with the range of ellipse minor axis

2. The code for drawing the intersection of a single ellipse image and a straight line is:
Plot[{gell}, {x, -a, a} /. params,
 Epilog -> {Red, PointSize[0.02], Point[gpts]}]

There isn't any error in replacing a value here. Why?

Reference resources: Comments by Alexei Boulbitch

3. Now, how can I integrate the line and ellipse images into a coordinate system?

The range of coordinates is automatically adjusted according to the value a and b of the major and minor axes of the ellipse. That's why the above replacement is used.

Code Update 1

ClearAll["`*"]
eqs = {x^2/16 + y^2/9 == 1, x == 2 y + 1};
line = eqs[[2]]
ell = eqs[[1]]
pts = SolveValues[{line, ell}, {x, y}];
normalized = First[ell] - Last[ell];
ax = Sqrt[Denominator[Coefficient[normalized, x^2]]]
bx = Sqrt[Denominator[Coefficient[normalized, y^2]]]
(*ass=ResourceFunction["EllipseProperties"][ell,{x,y}];
params={a->ass["SemimajorAxisLength"],b->ass["SemiminorAxisLength"]}*)\
params = {a -> Sqrt[Denominator[Coefficient[normalized, x^2]]],
  b -> Sqrt[Denominator[Coefficient[normalized, y^2]]]}
glin = line[[2]] /. params
gell = b {-1, 1} Sqrt[1 - x^2/a^2] /. params;
gpts = pts /. params;
(*Hold@ContourPlot[Evaluate@{eqs},{x,-a-1,a+1},{y,-b-0.5,b+0.5},\
PlotLegends->Placed[eqs,{0.8,0.15}],AspectRatio->Automatic,Frame->\
False,Axes->True,AxesStyle->Arrowheads[{0.0,0.04}],AxesLabel->{x,y}]/. \
params//ReleaseHold*)
ContourPlot[
 Evaluate@{eqs}, {x, -ax - 1, ax + 1}, {y, -bx - 0.5, bx + 0.5},
 Epilog -> {Red, PointSize[0.02], Point[gpts]},
 PlotLegends -> Placed[eqs, {0.8, 0.15}], AspectRatio -> Automatic,
 Frame -> False, Axes -> True, AxesStyle -> Arrowheads[{0.0, 0.04}],
 AxesLabel -> {x, y}]

Code Update 2

Clear["Global`*"]
eqs = {x^2/4 + y^2/3 == 1, y == 2 x + 1};
line = eqs[[2]]
ell = eqs[[1]]
pts = SolveValues[{line, ell}, {x, y}];
normalized = First[ell] - Last[ell];
ax = Sqrt[Denominator[Coefficient[normalized, x^2]]]
bx = Sqrt[Denominator[Coefficient[normalized, y^2]]]
p = Plot[y /. Solve[line, y], {x, -ax - 0.5, ax + 0.5}];
pts = SolveValues[{line, ell}, {x, y}]
Graphics[{{First@p}, {Red, Circle[{0, 0}, {ax, bx}],
   Point[{0, 0}]}, {Blue, PointSize[.03], Point[pts]}}, Axes -> True,
 AxesLabel -> {x, y}, AxesStyle -> Arrowheads[{0.0, 0.04}],
 AspectRatio -> 1]
plx = Apply[Subtract, eqs, {1}];
pls = Numerator[Together[Apply[Subtract, eqs, {1}]]];
xpl = Collect[Resultant[pls[[1]], pls[[2]], y], x];
Collect[Coefficient[xpl, x^2] x^2 +
   Factor@FactorTerms[Coefficient[xpl, x], x] x +
   Select[xpl, FreeQ[x]], x, # &, Defer[+##]~Reverse~2 &] == 0
Collect[xpl, x, Simplify];
pl = {% == 0}
discx = Factor[Discriminant[xpl, x]]   (*discriminant*)
frist = Solve[eqs, {x, y}] // FullSimplify;
{{x1, y1}, {x2, y2}} = {x, y} /. frist;
second = {x1 + x2, x1 x2, y1 + y2, y1 y2,
   y1 y2/(x1 x2), (x1 + x2)/2, (y1 + y2)/2} // FullSimplify
thrid = {x1 x2 + y1 y2, x1 y2 + x2 y1} // FullSimplify
slope = CoefficientList[line[[2]], x][[2]];    (*k*)
intercept = CoefficientList[line[[2]], x][[1]];  (*m*)
Chordlength =
 FullSimplify[
  Sqrt[1 + slope^2] Sqrt[(x1 + x2)^2 - 4 x1 x2]]    (*AbsAB*)
area = 1/2 Chordlength Sqrt[intercept^2]/Sqrt[slope^2 + 1] //
  FullSimplify
Peter Mortensen
  • 759
  • 4
  • 7
csn899
  • 3,953
  • 6
  • 13
  • ContourPlot[Evaluate@{x^2/16 + y^2/9 == 1, x == 2 y + 1}, {x, -5, 5}, {y, -5, 5}, PlotLegends -> Placed[eqns, {0.8, 0.15}]] – Bob Hanlon Jan 28 '23 at 01:41
  • thank you! I want to input the elliptic equation and the linear equation at the beginning, and then I will not input the elliptic equation and the linear equation for drawing and calculation, but directly use variables to extract. Includes the coordinate system x-axis y-axis range. It is better to draw the coordinate axis of the coordinate system. I have updated the problem. – csn899 Jan 28 '23 at 01:49
  • ContourPlot[ Evaluate@{x^2/16 + y^2/9 == 1, x == 2 y + 1}, {x, -5, 5}, {y, -5, 5}, PlotLegends -> Placed[eqns, {0.8, 0.15}], Axes -> True, AxesLabel -> {x, y}] – csn899 Jan 28 '23 at 02:17

4 Answers4

2
Clear["Global`*"]

eqns = {x^2/16 + y^2/9 == 1, x == 2 y + 1};

EDIT: Intersections are at

pts = SolveValues[eqns, {x, y}]

(* {{2/13 (2 - 3 Sqrt[51]), 3/26 (-3 - 2 Sqrt[51])}, {2/13 (2 + 3 Sqrt[51]), 3/26 (-3 + 2 Sqrt[51])}} *)

rng[var_] := Insert[(#[{var, eqns[[1]]}, {x, y}] & /@ {MinValue, MaxValue}), var, 1];

Module[{xrng = rng[x], yrng = rng[y]}, Show[ ContourPlot @@ {eqns, xrng, yrng, AspectRatio -> (Subtract @@ Rest@yrng)/(Subtract @@ Rest@xrng), Frame -> False, Axes -> True, AxesLabel -> Automatic}, Graphics[{Thin, Arrow[{1.1 #, 0} & /@ (Rest@xrng)], Arrow[{0, 1.13 #} & /@ (Rest@yrng)], Red, AbsolutePointSize[4], Tooltip[Point[#], N@#] & /@ pts}]]]

enter image description here

Bob Hanlon
  • 157,611
  • 7
  • 77
  • 198
2

can be drawn to the same coordinate system.

Why not just use Graphics? Note that the Circle command can also draw an ellipse!

Mathematica graphics

enter image description here

ClearAll["Global`*"];
a = 4;
b = 3
centerAt = {0, 0}
lineEq = x == 2 y + 1
p = Plot[y /. Solve[lineEq, y], {x, -a, a}];
Graphics[{{Dashed,First@p},{Red,Circle[centerAt,{a, b}], Point[centerAt]}},Axes->True]

How to add an arrow to the coordinate axis?

You can use AxesStyle

Graphics[{{Dashed, First@p},
  {Red, Circle[centerAt, {a, b}], Point[centerAt]}
  },
 Axes -> True, AxesStyle -> Arrowheads[{0.0, 0.04}]]

Mathematica graphics

How to show the intersection of line and ellipse

You can do similar to what Bob did which is use SolveValues and then use the Point command in the Graphics. Like this

ClearAll["Global`*"];
a = 4;
b = 3
centerAt = {0, 0}
lineEq = x == 2 y + 1
elipseEq = x^2/a^2 + y^2/b^2 == 1;
p = Plot[y /. Solve[lineEq, y], {x, -a, a}];
pts = SolveValues[{lineEq, elipseEq}, {x, y}]
Graphics[{
  {Dashed, First@p},
  {Red, Circle[centerAt, {a, b}], Point[centerAt]},
  {Blue, PointSize[.03], Point[pts]}
  },
 Axes -> True, AxesStyle -> Arrowheads[{0.0, 0.04}]]

Mathematica graphics

You can change the color, point size, etc.. as you want.

How to label the corresponding curve with the corresponding equation in the image

One way could be to use Text command and place the equations where you want them

Mathematica graphics

ClearAll["Global`*"];
a = 4;
b = 3
centerAt = {0, 0}
lineEq = x == 2 y + 1
elipseEq = x^2/a^2 + y^2/b^2 == 1;
p = Plot[y /. Solve[lineEq, y], {x, -a, a}];
pts = SolveValues[{lineEq, elipseEq}, {x, y}]
Graphics[{
  {Dashed, First@p},
  {Red, Circle[centerAt, {a, b}], Point[centerAt]},
  {Blue, PointSize[.03], Point[pts]},
  {Rotate[Text[lineEq, {2, .8}], 30 Degree], 
   Text[elipseEq, {1.4, 3.4}]}
  },
 Axes -> True, AxesStyle -> Arrowheads[{0.0, 0.04}]
 ]
Nasser
  • 143,286
  • 11
  • 154
  • 359
  • Circle command can also draw an ellipse.I remember this usage. thank you! How to add an arrow to the coordinate axis? – csn899 Jan 28 '23 at 02:47
  • @csn899 added arrows – Nasser Jan 28 '23 at 02:55
  • Thank you very much! This method can draw an ellipse! It's amazing!Graphics[Circle[{0, 0}, {4, 3}], Axes -> True, AxesLabel -> {x, y}] – csn899 Jan 28 '23 at 02:58
  • How to show the intersection of line and ellipse in the image. For example, the red dot represents the intersection of the two. – csn899 Jan 28 '23 at 03:41
  • @csn899 updated for intersection – Nasser Jan 28 '23 at 03:50
  • Which parameter should be changed when drawing a solid line instead of a dotted line? – csn899 Jan 28 '23 at 06:05
  • @csn899 Just remove the Dashed from the code, then it will become solid, which is the default. – Nasser Jan 28 '23 at 07:49
  • Clear["Global`*"] eqs = {x^2/4 + y^2/3 == 1, y == 2 x + 1}; line = eqs[[2]] ell = eqs[[1]] pts = SolveValues[{line, ell}, {x, y}]; normalized = First[ell] - Last[ell]; ax = Sqrt[Denominator[Coefficient[normalized, x^2]]] bx = Sqrt[Denominator[Coefficient[normalized, y^2]]] p = Plot[y /. Solve[line, y], {x, -ax - 0.5, ax + 0.5}]; pts = SolveValues[{line, ell}, {x, y}] Graphics[{{First@p}, {Red, Circle[{0, 0}, {ax, bx}], Point[{0, 0}]}, {Blue, PointSize[.03], Point[pts]}}, Axes -> True, AxesLabel -> {x, y}, AxesStyle -> Arrowheads[{0.0, 0.04}]] – csn899 Jan 28 '23 at 10:06
  • How to label the corresponding curve with the corresponding equation in the image? – csn899 Jan 28 '23 at 10:46
  • @csn899 updated for labels. – Nasser Jan 28 '23 at 11:11
2

Using Region functionality:

Clear[x, y, r1, r2]
r1 = ImplicitRegion[x^2/16 + y^2/9 == 1, {x, y}];
r2 = ImplicitRegion[x == 2 y + 1, {{x, -4, 4}, y}];

Show[{Region[r1], Region[r2] , Region[Style[ BooleanRegion[And, {r1, r2}] , AbsolutePointSize[6], Red] ] } , PlotRange -> {{-4.5, 4.5}, {-4, 4}} , AspectRatio -> Automatic , Frame -> False , Axes -> True , AxesLabel -> {x, y} , AxesStyle -> Arrowheads[{-0.04, 0.04}, {-0.04, 0.04}] ]

enter image description here

Syed
  • 52,495
  • 4
  • 30
  • 85
0
ContourPlot[
  Evaluate@{eqns}, {x, -a - 1, a + 1}, {y, -b - 0.5, b + 0.5}, 
  PlotLegends -> Placed[eqns, {0.8, 0.15}], AspectRatio -> Automatic, 
  Axes -> True, AxesLabel -> {x, y}] /. params

This code can show that lines and ellipses are in the same coordinate system, but why does this error prompt still appear

ContourPlot::plln: Limiting value -1-a in {x,-1-a,1+a} is not a machine-sized real number.

ContourPlot[
  Evaluate@{eqns}, {x, -a - 1, a + 1}, {y, -b - 0.5, b + 0.5}, 
  PlotLegends -> Placed[eqns, {0.8, 0.15}], AspectRatio -> Automatic, 
  Axes -> True, AxesLabel -> {x, y}, Frame -> False] /. params
csn899
  • 3,953
  • 6
  • 13
  • 1
    It's a matter of evaluation order. If you don't want to see it: Hold@ContourPlot[ Evaluate@{eqns}, {x, -a - 1, a + 1}, {y, -b - 0.5, b + 0.5}, PlotLegends -> Placed[eqns, {0.8, 0.15}], AspectRatio -> Automatic, Axes -> True, AxesLabel -> {x, y}] /. params//ReleaseHold – xzczd Jan 28 '23 at 03:51
  • How to modify this code can be shown to the intersection of line and ellipse in the image. For example, the red dot represents the intersection of the two. – csn899 Jan 28 '23 at 05:58
  • Please read Nasser's answer carefully。 – xzczd Jan 28 '23 at 07:13
  • {Blue, PointSize[.03], Point[pts] – csn899 Jan 28 '23 at 09:46
  • ContourPlot[ Evaluate@{eqs, {Red, PointSize[0.01], Point[pts]}}, {x, -ax - 1, ax + 1}, {y, -bx - 0.5, bx + 0.5}, PlotLegends -> Placed[eqs, {0.8, 0.15}], AspectRatio -> Automatic, Frame -> False, Axes -> True, AxesStyle -> Arrowheads[{0.0, 0.04}], AxesLabel -> {x, y}] – csn899 Jan 28 '23 at 09:55
  • Please read document of ContourPlot carefully by pressing F1, don't code blindly. – xzczd Jan 28 '23 at 10:56