ClearAll["Global`*"]

tC[x_] := x^3 - 24  x^2 + 204  x + 338

tC[x]

Plot[tC[x], {x, 0, 20}, PlotRange -> {0, 2500}, 
      AxesLabel -> {"\:751f\:7523\:91cf x", "\:7dcf\:8cbb\:7528 \
TC(x)"}, PlotLabel -> "\:7dcf\:8cbb\:7528\:66f2\:7dda"]

mC[x_] := Evaluate[D[tC[x], x]]

mC[x]

aC[x_] := Expand[tC[x]/x]

aC[x]

\( (*\ 平均可変費用曲線\ AVC \((x)\)\ *) \)

avC[x_] := Expand[(tC[x] - 338)/x]

avC[x]

Needs["Graphics`Legend`"]

Plot[{mC[x], aC[x], avC[x]}, {x, 0, 20}, PlotRange -> {0, 400}, 
      PlotStyle -> {{RGBColor[1, 0, 0]}, {RGBColor[0, 1, 0]}, {RGBColor[
              0, 0, 1]}}, 
      AxesLabel -> {"\:751f\:7523\:91cf x", "C(x)"}, 
      PlotLabel -> "\:5404\:8cbb\:7528\:66f2\:7dda", 
      PlotLegend -> {"MC(x)", "AC(y)", "AVC(y)"}, 
      LegendPosition -> {-0.3, 0.1}, 
      LegendSize -> {0.5, 0.3}]

Solve[mC[x] == aC[x], x]

tp = Solve[mC[x] == aC[x], x][[1]]

tpx = tp[[1, 2]]

tpC = aC[x] /. tp

tpball = Point[{tpx, tpC}]

tptext = 
      Text["\:640d\:76ca\:5206\:5c90\:70b9", {tpx + 3, 
          tpC + 10}]

tpw = Graphics[{{PointSize[0.05], tpball}, tptext}]

pe = 375

Solve[pe == mC[x], x]

qex = x /. Solve[pe == mC[x], x][[2]]

priceb[x_] := If[x < qex, pe, 0]

priceb[x]

aCpe = aC[qex]

aCbar[x_] := If[x < qex, aCpe, 0]

aCbar[x]

Needs["Graphics`FilledPlot`"]

gmtR = 
      FilledPlot[{mC[x], aC[x], avC[x], priceb[x]}, {x, 0, 20}, 
        PlotRange -> {0, 400}, Fills -> {{{4, Axis}, Hue[0.1]}}, 
        Curves -> Front, 
        PlotStyle -> {{RGBColor[1, 0, 0]}, {RGBColor[0, 1, 
                0]}, {RGBColor[0, 0, 1]}, {RGBColor[0, 0, 0]}}, 
        AxesLabel -> {"\:751f\:7523\:91cf x", "C(x)"}, 
        PlotLabel -> "\:5229\:6f64\:6700\:5927\:5316\:306e\:3068\:304d\
\:306e\:7dcf\:53ce\:5165 TR(xast)"]

Show[gmtR, tpw]

gmtC = 
      FilledPlot[{mC[x], aC[x], avC[x], aCbar[x]}, {x, 0, 20}, 
        PlotRange -> {0, 400}, Fills -> {{{4, Axis}, Hue[0.8]}}, 
        Curves -> Front, 
        PlotStyle -> {{RGBColor[1, 0, 0]}, {RGBColor[0, 1, 
                0]}, {RGBColor[0, 0, 1]}, {RGBColor[0, 0, 0]}}, 
        AxesLabel -> {"\:751f\:7523\:91cf x", "C(x)"}, 
        PlotLabel -> "\:5229\:6f64\:6700\:5927\:5316\:306e\:3068\:304d\
\:306e\:7dcf\:8cbb\:7528 TC(xast)"]

Show[gmtC, tpw]

gmtPI = 
      FilledPlot[{mC[x], aC[x], avC[x], priceb[x], aCbar[x]}, {x, 0, 20}, 
        PlotRange -> {0, 400}, Fills -> {{{4, 5}, Hue[0.5]}}, 
        Curves -> Front, 
        PlotStyle -> {{RGBColor[1, 0, 0]}, {RGBColor[0, 1, 
                0]}, {RGBColor[0, 0, 1]}, {RGBColor[0, 0, 0]}, {RGBColor[0, 
                0, 0]}}, 
        AxesLabel -> {"\:751f\:7523\:91cf x", "C(x)"}, 
        PlotLabel -> "\:5229\:6f64\:6700\:5927\:5316\:306e\:3068\:304d\
\:306e\:7dcf\:5229\:6f64 PI(xast)"]

Show[gmtPI, tpw]

gmtCtPI = 
      FilledPlot[{mC[x], aC[x], avC[x], priceb[x], aCbar[x]}, {x, 0, 20}, 
        PlotRange -> {0, 400}, 
        Fills -> {{{5, Axis}, Hue[0.8]}, {{4, 5}, Hue[0.5]}}, 
        Curves -> Front, 
        PlotStyle -> {{RGBColor[1, 0, 0]}, {RGBColor[0, 1, 
                0]}, {RGBColor[0, 0, 1]}, {RGBColor[0, 0, 0]}, {RGBColor[0, 
                0, 0]}, {RGBColor[0, 0, 0]}}, 
        AxesLabel -> {"\:751f\:7523\:91cf x", "C(x)"}, 
        PlotLabel -> "\:5229\:6f64\:6700\:5927\:5316\:306e\:3068\:304d\
\:306e\:7dcf\:8cbb\:7528 TC(x*) \:3068\:7dcf\:5229\:6f64 PI(xast)"]

Show[gmtCtPI, tpw]

\( (*\ 価格を変えて利潤最大化のときの総費用\ TC \((xast)\)\ と総利潤\ PI \((xast)\)\ \ のアニメ - ション\ *) \)

Solve[px == mC[x], x]

Solve[px == mC[x], x][[2]]

qm[px_] := x /. Solve[px == mC[x], x][[2]]

qm[px]

pbchg[x_, px_] := If[x < qm[px], px, 0]

pbchg[x, px]

aCbchg[x_, px_] := If[x < qm[px], Evaluate[aC[qm[px]]], 0]

aCbchg[x, px]

Table[
      FilledPlot[{mC[x], aC[x], avC[x], aCbchg[x, px], pbchg[x, px]}, {x, 0, 
          20}, PlotRange -> {0, 400}, 
        Fills -> {{{4, Axis}, Hue[0.8]}, {{5, 4}, Hue[0.5]}}, 
        Curves -> Front, 
        PlotStyle -> {{RGBColor[1, 0, 0]}, {RGBColor[0, 1, 
                0]}, {RGBColor[0, 0, 1]}, {RGBColor[0, 0, 0]}, {RGBColor[0, 
                0, 0]}, {RGBColor[0, 0, 0]}}, 
        AxesLabel -> {"x", "C(x)"}, 
        PlotLabel -> "TC(xast) \:3068 PI(xast)"], {px, 100, 350, 
        50}]