ClearAll["Global`*"]

u[x1_, x2_] := x1^0.5  x2^0.5

ug = 
      Plot3D[u[x1, x2], {x1, 0, 40}, {x2, 0, 40}, PlotPoints -> 35, 
        PlotRange -> {0, 
            40}, 
PlotLabel -> "\:52b9\:7528\:95a2\
\:6570\:306e\:4e09\:6b21\:5143\:30b0\:30e9\:30d5", 
        AxesLabel -> {"x1 (\:91cf)", "x2 (\:91cf)", "U (\:52b9\
\:7528)"}]

bgc[x1_, x2_] := 10*x1 + 20*x2

Solve[bgc[x1, x2] == 300, x2]

solx2 = Solve[bgc[x1, x2] == 300, x2][[1]]

x2bgc[x1_] := Evaluate[x2 /. solx2]

x2bgc[x1]

\(bgcwall = 
      ParametricPlot3D[{x1, x2bgc[x1], bgctall}, {x1, 0, 30}, {bgctall, 0, 
          15}, PlotLabel -> "予算制約式の三次元グラフ", AxesLabel -> {"x1 (量)", "x2 (量)", "高さ"}]\)

Show[ug, bgcwall, 
      PlotLabel -> "\:52b9\:7528\:95a2\:6570\:3068\:4e88\:7b97\:5236\
\:7d04\:5f0f\:306e\:4e09\:6b21\:5143\:30b0\:30e9\:30d5", 
      AxesLabel -> {"x1", "x2",  "U"}]

lgr[x1_, x2_, lmd_] := 
      u[x1, x2] + lmd*(300 - (10*x1 + 20*x2))

focx1 = (D[lgr[x1, x2, lmd], x1] == 0)

focx2 = (D[lgr[x1, x2, lmd], x2] == 0)

foclmd = (D[lgr[x1, x2, lmd], lmd] == 0)

solfoc = Solve[{focx1, focx2, foclmd}, {x1, x2, 
            lmd}][[1]]

x1max = x1 /. solfoc

x2max = x2 /. solfoc

umax = Evaluate[u[x1, x2] /. solfoc]

umball = Point[{x1max, x2max, umax}]

umtext = 
      Text["\:52b9\:7528\:6700\:5927\:5316\:70b9", {x1max + 5, x2max + 5, 
          umax + 10}]

Show[ug, bgcwall, Graphics3D[{PointSize[0.05], Hue[0], umball}], 
      Graphics3D[{Hue[0.5], umtext}], 
      PlotLabel -> "\:52b9\:7528\:6700\:5927\:5316\:70b9\:306e\:56f3\
\:793a", AxesLabel -> {"x1", "x2",  "U"}]

Solve[u[x1, x2] == umax, x2]

solx2um = Solve[u[x1, x2] == umax, x2][[1]]

x2um[x1_] := Evaluate[x2 /. solx2um]

x2um[x1]

cg1 = 
      ParametricPlot3D[{x1, x2um[x1], umax, Thickness[0.01]}, {x1, 2.5, 40}, 
        PlotRange -> {{2.5, 40}, {2.5, 40}, {0, 40}}, 
        PlotLabel -> "\:52b9\:7528\:6700\:5927\:5316\:70b9\:3092\:901a\
\:308b\:7121\:5dee\:5225\:66f2\:7dda", 
        AxesLabel -> {"x1", "x2",  "U"}]

Show[ug, bgcwall, Graphics3D[{PointSize[0.05], Hue[0], umball}], 
      Graphics3D[{Hue[0.5], umtext}], cg1, 
      PlotLabel -> "\:52b9\:7528\:95a2\:6570,\:4e88\:7b97\:5236\:7d04\
\:5f0f,\:52b9\:7528\:6700\:5927\:5316\:70b9\:3092\:901a\:308b\:7121\:5dee\
\:5225\:66f2\:7dda", 
      AxesLabel -> {"x1", "x2",  "U"}]

\(gutil[pm_] := 
      Show[ug, bgcwall, Graphics3D[{PointSize[0.05], Hue[0], umball}], 
        Graphics3D[{Hue[0.5], umtext}], cg1, 
        ViewPoint -> {pm, \(-2.4\), 2}, 
        PlotLabel -> "効用関数,予算制約式,無差別曲線の視点を変える", 
        AxesLabel -> {"x1", "x2", \ "U"}]\)

Show[Table[gutil[pm], {pm, 1, -0.5, -0.5}]]

Solve[u[x1, x2] == ubar, x2]

solx2ub = Solve[u[x1, x2] == ubar, x2][[1]]

x2ub[x1_, ubar_] := Evaluate[x2 /. solx2ub]

x2ub[x1, ulev]

\(cgtbl = 
      ParametricPlot3D[
        Evaluate[
          Table[{x1, x2ub[x1, ulev], ulev, Thickness[0.015]}, {ulev, 0, 40, 
              5}]], {x1, 2.5, 40}, 
        PlotRange -> {{2.5, 40}, {2.5, 40}, {0, 40}}, 
        PlotLabel -> "無差別曲線群(三次元)", 
        AxesLabel -> {"x1", "x2", \ "U"}]\)

Show[ug, bgcwall, cgtbl, 
      PlotRange -> {{2.5, 40}, {2.5, 40}, {0, 40}}, 
      PlotLabel -> "\:52b9\:7528\:95a2\:6570,\:4e88\:7b97\:5236\:7d04\
\:3068\:7121\:5dee\:5225\:66f2\:7dda\:7fa4", 
      AxesLabel -> {"x1", "x2",  "U"}]

cpg1 = 
      ContourPlot[u[x1, x2], {x1, 0, 40}, {x2, 0, 40}, 
        PlotLabel -> "\:7121\:5dee\:5225\:66f2\:7dda\:7fa4\:306e\:4e8c\
\:6b21\:5143\:63cf\:753b(\:6fc3\:5ea6\:4ed8\:304d)", 
        FrameLabel -> {"x1", "x2"}]

cpg2 = 
      ContourPlot[u[x1, x2], {x1, 0, 40}, {x2, 0, 40}, 
        ContourShading -> False, PlotPoints -> 50, 
        PlotLabel -> "\:7121\:5dee\:5225\:66f2\:7dda\:7fa4\:306e\:4e8c\
\:6b21\:5143\:63cf\:753b(\:6fc3\:5ea6\:306a\:3057)", 
        FrameLabel -> {"x1", "x2"}]

<< Graphics`ImplicitPlot`

bgcg = 
      ImplicitPlot[bgc[x1, x2] == 300, {x1, 0, 40}, {x2, 0, 40}, 
        PlotStyle -> Thickness[0.01], 
        PlotLabel -> "\:4e88\:7b97\:5236\:7d04\:5f0f", 
        AxesLabel -> {"x1", "x2"}]

Show[cpg2, bgcg, 
      PlotLabel -> "\:7121\:5dee\:5225\:66f2\:7dda\:7fa4\:3068\:4e88\
\:7b97\:5236\:7d04\:5f0f", 
      FrameLabel -> {"x1", "x2"}]

cpmg = 
      ImplicitPlot[u[x1, x2] == umax, {x1, 0, 40}, {x2, 0, 40}, 
        PlotLabel -> "\:52b9\:7528\:6700\:5927\:5316\:70b9\:3092\:901a\
\:308b\:7121\:5dee\:5225\:66f2\:7dda(\:4e8c\:6b21\:5143)", 
        AxesLabel -> {"x1", "x2"}]

umball2 = Point[{x1max, x2max}]

umtext2 = 
      Text["\:52b9\:7528\:6700\:5927\:5316\:70b9", {x1max + 3, 
          x2max + 3}]

Show[cpmg, bgcg, Graphics[{PointSize[0.05], Hue[0.7], umball2}], 
      Graphics[umtext2], 
      PlotLabel -> "\:52b9\:7528\:6700\:5927\:5316\:70b9\:3092\:901a\
\:308b\:7121\:5dee\:5225\:66f2\:7dda\:3068\:4e88\:7b97\:5236\:7d04\:5f0f", 
      AxesLabel -> {"x1", "x2"}]