1

だから私は平面上の線を指定する一連の有界ディオファントス方程式を持っています。これらの方程式の2つの共通部分を数学でプロットして、それらがどのように見えるかを確認したいと思います。

これまでのところ、私は次のようなものを持っています:

Solve [0 <x --y <3 && -1 <2 x --y <2、{x、y}、整数]

これは次のような構造を返します:

{{x-> -2、y-> -4}、{x-> -1、y-> -3}、{x-> -1、y-> -2}、{x-> 0、y -> -1}}

しかし、どうすればこれを数学でプロットして、結果の形状を見ることができますか?できれば、プロットですべての「点」を1x1の正方形と見なしたいと思います。

また、そのようなことをするためのより良い方法があるのだろうかと思います。ありがとう。

4

2 に答える 2

2

リストの戻り値を変換して、プロットするデータを定義しSolve[]ます。これは次のように行うことができます

 data = {x, y} /. Solve[0 < x - y < 3 && -1 < 2 x - y < 2, {x, y}, Integers]

Solveより一般的には、次のトリックを使用して、(ルールのセットとしてではなく)リスト形式でソリューションを返すことができます。

 data = Solve[0 < x - y < 3 && -1 < 2 x - y < 2, {x, y}, Integers] /. Rule[a_,b_]->b

ListPlotプロットの場合、多くの選択肢の中で、次のように使用できます

ListPlot[data, PlotMarkers -> {Style["\[FilledSquare]", FontSize -> 16]}]

次の出力を取得するには

出力画像

の多くのスタイリングやその他のオプションを使用して、さらに洗練することができますListPlot。たとえば、ポイントに参加できます

ListPlot[data, PlotMarkers -> {Style["\[FilledSquare]", FontSize -> 16]}, 
 Joined -> True]

取得するため

結合されたプロット

編集:マーカーの配置とサイズを試すには、いくつかの選択肢があります。を使用ListPlotすると、次の2つの方法のいずれかで必要なものを取得できます。

 (* Alternative 1: use fontsize to change the marker size *)
 lp1 := ListPlot[{#} & /@ #1, 
 PlotMarkers -> {Style["\[FilledSquare]", FontSize -> Scaled[#2]]},
 AspectRatio -> 1, AxesOrigin -> {0, 0}, 
 PlotRange -> {{-5, 1}, {-5, 1}}, 
 PlotStyle -> Hue /@ RandomReal[1, {Length@#1}], 
 Epilog -> {GrayLevel[.3], PointSize[.02], Point@#1, Thick, 
  Line@#1}, Frame -> True, FrameTicks -> All] &;
 (* usage example *)
 lp1 @@ {data, .30}

 (* Alternative 2: use the second parameter of PlotMarkers to control scaled size *)
 lp2 := ListPlot[{#} & /@ #1, 
 PlotMarkers -> {Graphics@{Rectangle[]}, #2}, AspectRatio -> 1, 
 AxesOrigin -> {0, 0}, PlotRange -> {{-5, 1}, {-5, 1}}, 
 PlotStyle -> Hue /@ RandomReal[1, {Length@#1}], 
 Epilog -> {GrayLevel[.3], PointSize[.02], Point@#1, Thick, 
 Line@#1}, Frame -> True, FrameTicks -> All] &
 (* usage example *)
 lp2 @@ {data, 1/5.75}

どちらの場合も、を使用する必要がありますEpilog。そうしないと、ポイントを結ぶ線がマーカーによって遮られます。どちらの方法でも、次の出力が生成されます。

マーカー付きリストプロット

または、の適切な変換を使用して、、、を使用してGraphics、上記の出力と同様の結果を得ることができます。RegionPlotContourPlotBubbleChartdataListPlot

グラフィックプリミティブの使用:

 (* data transformation to define the regions *)
 trdataG[data_, size_] :=  data /. {a_, b_} :> 
         {{a - size/2, b - size/2}, {a + size/2, b + size/2}};
 (* plotting function *)
 gr := Graphics[
      {
      {Hue[RandomReal[]], Rectangle[##]} & @@@ trdataG @@ {#1, #2}, 
      GrayLevel[.3], PointSize[.02], Thick, Point@#1, Line@#1}, 
      PlotRange -> {{-5, 1}, {-5, 1}
      }, 
      PlotRangePadding -> 0, Axes -> True, AxesOrigin -> {0, 0}, 
      Frame -> True, FrameTicks -> All] &
 (* usage example *)
 gr @@ {data, .99}

BubbleChartの使用:

 (* Transformation of data to a form that BubbleChart expects *)
 dataBC[data_] := data /. {a_, b_} :> {a, b, 1};
 (* custom markers *)
 myMarker[size_][{{xmin_, xmax_}, {ymin_, ymax_}}, ___] :=
      {EdgeForm[], Rectangle[{(1/2) (xmin + xmax) - size/2, (1/2) (ymin + ymax) - 
       size/2}, {(1/2) (xmin + xmax) + size/2, (1/2) (ymin + ymax) + size/2}]};
 (* charting function *)
 bc := BubbleChart[dataBC[#1], ChartElementFunction -> myMarker[#2], 
       ChartStyle -> Hue /@ RandomReal[1, {Length@#1}], Axes -> True, 
       AxesOrigin -> {0, 0}, PlotRange -> {{-5, 1}, {-5, 1}}, 
       PlotRangePadding -> 0, AspectRatio -> 1, FrameTicks -> All, 
       Epilog -> {GrayLevel[.3], PointSize[.02], Point@#1, Thick, Line@#1}] &
 (* usage example *)
 bc @@ {data, .99}

RegionPlotの使用:

 (* Transformation of data to a form that RegionPlot expects *)
  trdataRP[data_, size_] :=  data /. {a_, b_} :> 
            a - size/2 <= x <= a + size/2 && b - size/2 <= y <= b + size/2
 (* charting function *)
 rp := RegionPlot[Evaluate@trdataRP[#1, #2], {x, -5, 1}, {y, -5, 1}, 
          AspectRatio -> 1, Axes -> True, AxesOrigin -> {0, 0}, 
          PlotRange -> {{-5, 1}, {-5, 1}}, 
          PlotStyle -> Hue /@ RandomReal[1, {Length@#1}], FrameTicks -> All, 
          PlotPoints -> 100, BoundaryStyle -> None, 
          Epilog -> {GrayLevel[.3], PointSize[.02], Point@#1, Thick, Line@#1}] &
 (* usage example *)
 rp @@ {data, .99}

ContourPlotの使用:

 (* Transformation of data to a form that ContourPlot expects *)
 trdataRP[data_, size_] :=   data /. {a_, b_} :> 
            a - size/2 <= x <= a + size/2 && b - size/2 <= y <= b + size/2;
 trdataCP[data_, size_] := Which @@ Flatten@
           Thread[{trdataRP[data, size], Range@Length@data}];
 (* charting function *)
 cp := ContourPlot[trdataCP[#1, #2], {x, -5, 1}, {y, -5, 1}, 
             AspectRatio -> 1, Axes -> True, AxesOrigin -> {0, 0}, 
             PlotRange -> {{-5, 1}, {-5, 1}}, FrameTicks -> All, 
             ExclusionsStyle -> None, PlotPoints -> 100, 
             ColorFunction -> Hue, 
             Epilog -> {GrayLevel[.3], PointSize[.02], Point@#1, Thick, Line@#1}] &
 (* usage example *)
 cp @@ {data, .99}
于 2012-01-26T01:57:22.550 に答える
1

多分

sol = Solve[0 < x - y < 3 && -1 < 2 x - y < 2, {x, y}, Integers];
pts = Cases[sol, {_ -> n_, _ -> m_} :> {n, m}];
ListPlot[pts, Mesh -> All, Joined -> True, AxesOrigin -> {0, 0}, 
 PlotMarkers -> {Automatic, 10}]

ここに画像の説明を入力してください

を使用してプロットするポイントを抽出することもできます

{#[[1, 2]], #[[2, 2]]} & /@ sol
于 2012-01-26T01:49:16.263 に答える