2
$\begingroup$

I have the following code:

f1[x_] := 1.333 + 28.846/x
f2[x_] := 1.333 + 28.846/(115/Sqrt[3])
f3[x_] := 1.333 + 28.846/(115/Sqrt[3])

plotData = {{53.1, 2.026}, {54.8, 1.679}, {56.4, 1.582}, {58.1, 
    1.597}, {59.8, 2.013}, {61.4, 1.993}, {63.1, 1.952}, {64.7, 
    1.867}, {66.4, 1.819}, {68.1, 1.862}, {69.7, 1.733}, {71.4, 
    1.692}, {73, 1.726}, {74.7, 1.697}, {76.4, 1.654}, {78, 
    1.672}, {79.7, 1.596}};


plt = Plot[{f1[x], f2[x], f3[x]}, {x, 0, 90},
  Epilog -> Map[Point, plotData],
  PlotRange -> {{45, 90}, {1, 3}},
  PlotStyle -> {Blue, Directive[Black, Dashed], 
    Directive[Black, Dashed]},
  PlotTheme -> "Scientific",
  PlotLegends -> {
    SwatchLegend[{HatchFilling[Pi/4, 1, 
       5], {HatchFilling[-Pi/4, 4, 12], 
       Blue}}, {"\!\(\*SubscriptBox[\(S\), \(neg\)]\)", 
      "\!\(\*SubscriptBox[\(S\), \(pos\)]\)"}, 
     LegendMarkerSize -> 30]},
  ImageSize -> Large,
  LabelStyle -> 
   Directive[Black, FontSize -> 14, FontFamily -> "Times New Roman"],
  FrameLabel -> {Style["U", Bold, Black, FontSize -> 14],
    Style["K", Bold, Black, FontSize -> 14]},
  Filling -> {
    {1 -> {{2}, {{HatchFilling[-Pi/4, 4, 12], Blue}, 
        HatchFilling[Pi/4, 1, 5]}}}}];


dataPointCross = {{115/Sqrt[3], f1[115/Sqrt[3]]}};
PointCross = ListPlot[dataPointCross,
  PlotStyle -> {Red, PointSize[0.015]}];


Show[{plt, PointCross}]

The result: enter image description here

I wanted to integrate regions Sneg and Spos up to the red point (within the limits on the Plot: from 0.8*115/Sqrt[3] to 1.0*115/Sqrt[3] and from 1.0*115/Sqrt[3] to 1.2*115/Sqrt[3] for Sneg and Spos respectively) but couldn't find the way besides through Piecewise. So I tried to create the closed region:

Plot[Piecewise[{{f1[x], 0.8*115/Sqrt[3] <= x <= 115/Sqrt[3]}, {f2[x], 
    x <= 115/Sqrt[3]}}, 115/Sqrt[3]], {x, 0.7*115/Sqrt[3], 
  1.1*115/Sqrt[3]},
 PlotRange -> {{0.7*115/Sqrt[3], 1.1*115/Sqrt[3]}, {1, 3}}]

enter image description here

Q1. It seems that I failed doing that. And I even don't understand what's going on - why the region is not closed?

Q2. Probably, it's possible to integrate regions without Piecewise. Any help is highly valuable.

$\endgroup$

1 Answer 1

6
$\begingroup$
$Version

(* "14.0.0 for Mac OS X ARM (64-bit) (December 13, 2023)" *)

Clear["Global`*"];

f1[x_] := 1.333 + 28.846/x;
f2[x_] := 1.333 + 28.846/(115/Sqrt[3]);

plotData = {{53.1, 2.026}, {54.8, 1.679}, {56.4, 1.582}, {58.1, 
    1.597}, {59.8, 2.013}, {61.4, 1.993}, {63.1, 1.952}, {64.7, 
    1.867}, {66.4, 1.819}, {68.1, 1.862}, {69.7, 1.733}, {71.4, 
    1.692}, {73, 1.726}, {74.7, 1.697}, {76.4, 1.654}, {78, 
    1.672}, {79.7, 1.596}};

dataPointCross = {115/Sqrt[3], f1[115/Sqrt[3]]};

plt = Plot[{f1[x], f2[x]}, {x, 0, 90},
   Epilog -> {Point@plotData, Red, PointSize[0.015], 
     Point@dataPointCross},
   PlotRange -> {{45, 90}, {1, 3}},
   PlotStyle -> {Blue, Directive[Black, Dashed]},
   PlotTheme -> "Scientific",
   PlotLegends -> {
     Placed["Expressions", {.8, .8}],
     SwatchLegend[{HatchFilling[Pi/4, 1, 
        5], {HatchFilling[-Pi/4, 4, 12], 
        Blue}}, {"\!\(\*SubscriptBox[\(S\), \(neg\)]\)", 
       "\!\(\*SubscriptBox[\(S\), \(pos\)]\)"}, 
      LegendMarkerSize -> 30]},
   ImageSize -> Large, 
   LabelStyle -> 
    Directive[Black, FontSize -> 14, FontFamily -> "Times New Roman"],
    FrameLabel -> {Style["U", Bold, Black, FontSize -> 14], 
     Style["K", Bold, Black, FontSize -> 14]}, 
   Filling -> {{1 -> {{2}, {{HatchFilling[-Pi/4, 4, 12], Blue}, 
         HatchFilling[Pi/4, 1, 5]}}}}];

To calculate the areas

areaSneg = Integrate[f1[x] - f2[x], {x, 0.8*115/Sqrt[3], 115/Sqrt[3]}]

(* 0.667599 *)

rgnSneg = 
  ImplicitRegion[
   f2[x] < y < f1[x] && (0.8*115/Sqrt[3]) < x < 115/Sqrt[3], {x, y}];

Integrate[1, {x, y} ∈ rgnSneg]

(* 0.667599 *)

Area[DiscretizeRegion[rgnSneg, MaxCellMeasure -> {"Length" -> .01}]]

(* 0.667599 *)

Similarly,

areaSpos = Integrate[f2[x] - f1[x], {x, 115/Sqrt[3], 1.2*115/Sqrt[3]}]

(* 0.509952 *)

rgnSpos = 
  ImplicitRegion[
   f1[x] < y < f2[x] && 115/Sqrt[3] < x < (1.2*115/Sqrt[3]), {x, y}];

Integrate[1, {x, y} ∈ rgnSpos]

(* 0.509952 *)

Area[DiscretizeRegion[rgnSpos, MaxCellMeasure -> {"Length" -> .01}]]

(* 0.509952 *)

Graphically,

Show[plt, Region[Style[rgnSneg, Opacity[0.25, Blue]]], 
 Region[Style[rgnSpos, Opacity[0.25, Red]]]]

enter image description here

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.