목차
回复内容:
백엔드 개발 파이썬 튜토리얼 如何用数学软件画一个“圣诞树”?

如何用数学软件画一个“圣诞树”?

Jun 06, 2016 pm 04:22 PM

可以是字符的,也可以是图形的

相关问题如何用C语言画一个“圣诞树”? - 编程

回复内容:

我只是搬运codegolf.stackexchange.com上的答案,原作者是Silvia (@Silvia ),用的是Mathematica。
PD = .5;
s[t_, f_] := t^.6 - f
dt[cl_, ps_, sg_, hf_, dp_, f_, flag_] :=
    Module[{sv, basePt},
           {PointSize[ps],
            sv = s[t, f];
            Hue[cl (1 + Sin[.02 t])/2, 1, .3 + sg .3 Sin[hf sv]],
            basePt = {-sg s[t, f] Sin[sv], -sg s[t, f] Cos[sv], dp + sv};
            Point[basePt],
           If[flag,
              {Hue[cl (1 + Sin[.1 t])/2, 1, .6 + sg .4 Sin[hf sv]], PointSize[RandomReal[.01]],
               Point[basePt + 1/2 RotationTransform[20 sv, {-Cos[sv], Sin[sv], 0}][{Sin[sv], Cos[sv], 0}]]},
              {}]
          }]

frames = ParallelTable[
                       Graphics3D[Table[{
                                         dt[1, .01, -1, 1, 0, f, True], dt[.45, .01, 1, 1, 0, f, True],
                                         dt[1, .005, -1, 4, .2, f, False], dt[.45, .005, 1, 4, .2, f, False]},
                                        {t, 0, 200, PD}],
                                  ViewPoint -> Left, BoxRatios -> {1, 1, 1.3}, 
                                  ViewVertical -> {0, 0, -1},
                                  ViewCenter -> {{0.5, 0.5, 0.5}, {0.5, 0.55}}, Boxed -> False,
                                  PlotRange -> {{-20, 20}, {-20, 20}, {0, 20}}, Background -> Black],
                       {f, 0, 1, .01}];

Export["tree.gif", frames]
로그인 후 복사
Mathematica版本:
打开一个notebook,然后长按CTRL+/,效果如下:
如何用数学软件画一个“圣诞树”?像不像一棵圣诞树呢? 这里有用SAS画的圣诞树,翻译成了Mathematica版的
如何用数学软件画一个“圣诞树”?
Clear["`*"];
ifs[prob_,A_,init_,max_]:=FoldList[#2.{#[[1]],#[[2]],1}&,init,RandomChoice[prob->A,max]];

L={{{0.03,0},{0,0.1}},{{0.85,0},{0,0.85}},{{0.8,0},{0,0.8}},{{0.2,-0.08},{0.15,0.22}},{{-0.2,0.08},{0.15,0.22}},{{0.25,-0.1},{0.12,0.25}},{{-0.2,0.1},{0.12,0.2}}};
B=Map[List,{{0,0},{0,1.5},{0,1.5},{0,0.85},{0,0.85},{0,0.3},{0,0.4}},{2}];

{A,prob,init,max}={N@Join[L,B,3],{2,60,10,7,7,7,7}/100.,{0.,2.},10^5};
pts=ifs[prob,A,init,max];//AbsoluteTiming
Graphics[{{Darker@Green,PointSize@Tiny,Point@pts},{Hue@Random[],PointSize@Large,Point@#}&/@RandomChoice[pts,200]},AspectRatio->1.5]
로그인 후 복사
去年用R画了圣诞树送给教定量入门的教授,改了一下Wiekvoet: Merry Christmas的代码。
( 今年直接手动涂色送happy spring的卡片了,不是程序媛搞不出酷炫的东西好桑心) Wolfram Mathematica 算数学软件吧?

如何用数学软件画一个“圣诞树”?
还有这个:

如何用数学软件画一个“圣诞树”?
算不算抖机灵 = = 鸡汁的我
如何用数学软件画一个“圣诞树”? MATLAB ,名副其实的数学软件。
如何用数学软件画一个“圣诞树”?参考 File Exchange
by Anselm Ivanovas
====================================
%
<span class="k">function</span> <span class="nf">christmas</span>
<span class="c">% Anselm Ivanovas, anselm.ivanovas@student.unisg.ch</span>
<span class="c">%Basically just a nice plot for some christmas fun.</span>
<span class="c">%3D Plot of a hhristmas tree with some presents and snow</span>
<span class="c">%% setup</span>
<span class="n">snow</span><span class="p">=</span><span class="mi">800</span><span class="p">;</span> <span class="c">% number of snow flakes [0 .. 5000]</span>

<span class="c">%% draw tree</span>
<span class="n">h</span><span class="p">=</span><span class="mi">0</span><span class="p">:</span><span class="mf">0.2</span><span class="p">:</span><span class="mi">25</span><span class="p">;</span> <span class="c">%vertical grid</span>
<span class="p">[</span><span class="n">X</span><span class="p">,</span><span class="n">Y</span><span class="p">,</span><span class="n">Z</span><span class="p">]</span> <span class="p">=</span> <span class="n">cylinder</span><span class="p">(</span><span class="n">tree</span><span class="p">(</span><span class="n">h</span><span class="p">));</span> <span class="c">%produce a tree formed cylinder</span>
<span class="n">Z</span><span class="p">=</span><span class="n">Z</span><span class="o">*</span><span class="mi">25</span><span class="p">;</span> <span class="c">%scale to the right heigth</span>
<span class="c">%add some diffusion to the surface of the tree to make it look more real</span>
<span class="n">treeDiffusion</span><span class="p">=</span><span class="nb">rand</span><span class="p">(</span><span class="mi">126</span><span class="p">,</span><span class="mi">21</span><span class="p">)</span><span class="o">-</span><span class="mf">0.5</span><span class="p">;</span><span class="c">%some horizontal diffusion data</span>
<span class="c">%add diffusion to the grid points</span>
<span class="k">for</span> <span class="n">cnt1</span><span class="p">=</span><span class="mi">1</span><span class="p">:</span><span class="mi">21</span>

<span class="k">for</span> <span class="n">cnt2</span><span class="p">=</span><span class="mi">16</span><span class="p">:</span><span class="mi">126</span><span class="c">%starting above the trunk</span>
<span class="c">%get the angle to always diffuse in direction of the radius</span>
<span class="nb">angle</span><span class="p">=</span><span class="nb">atan</span><span class="p">(</span><span class="n">Y</span><span class="p">(</span><span class="n">cnt2</span><span class="p">,</span><span class="n">cnt1</span><span class="p">)</span><span class="o">/</span><span class="n">X</span><span class="p">(</span><span class="n">cnt2</span><span class="p">,</span><span class="n">cnt1</span><span class="p">));</span>
<span class="c">%split the diffusion in the two coordinates, depending on the angle</span>
<span class="n">X</span><span class="p">(</span><span class="n">cnt2</span><span class="p">,</span><span class="n">cnt1</span><span class="p">)=</span><span class="n">X</span><span class="p">(</span><span class="n">cnt2</span><span class="p">,</span><span class="n">cnt1</span><span class="p">)</span><span class="o">+</span><span class="nb">cos</span><span class="p">(</span><span class="nb">angle</span><span class="p">)</span><span class="o">*</span><span class="n">treeDiffusion</span><span class="p">(</span><span class="n">cnt2</span><span class="p">,</span><span class="n">cnt1</span><span class="p">);</span>
<span class="n">Y</span><span class="p">(</span><span class="n">cnt2</span><span class="p">,</span><span class="n">cnt1</span><span class="p">)=</span><span class="n">Y</span><span class="p">(</span><span class="n">cnt2</span><span class="p">,</span><span class="n">cnt1</span><span class="p">)</span><span class="o">+</span><span class="nb">sin</span><span class="p">(</span><span class="nb">angle</span><span class="p">)</span><span class="o">*</span><span class="n">treeDiffusion</span><span class="p">(</span><span class="n">cnt2</span><span class="p">,</span><span class="n">cnt1</span><span class="p">);</span>
<span class="c">%some Vertical diffusion for each point</span>
<span class="n">Z</span><span class="p">(</span><span class="n">cnt2</span><span class="p">,</span><span class="n">cnt1</span><span class="p">)=</span><span class="n">Z</span><span class="p">(</span><span class="n">cnt2</span><span class="p">,</span><span class="n">cnt1</span><span class="p">)</span><span class="o">+</span><span class="p">(</span><span class="nb">rand</span><span class="o">-</span><span class="mf">0.5</span><span class="p">)</span><span class="o">*</span><span class="mf">0.5</span><span class="p">;</span>
<span class="k">end</span>

<span class="k">end</span>
<span class="c">%draw the tree</span>
<span class="n">surfl</span><span class="p">(</span><span class="n">X</span><span class="p">,</span><span class="n">Y</span><span class="p">,</span><span class="n">Z</span><span class="p">,</span><span class="s">'light'</span><span class="p">)</span>
<span class="c">%% View and format</span>
<span class="c">%Use as nice green color map (darker at the bottom, lighter at the top)</span>
<span class="n">r</span><span class="p">=(</span><span class="mf">0.0430</span><span class="p">:(</span><span class="mf">0.2061</span><span class="o">/</span><span class="mi">50</span><span class="p">):</span><span class="mf">0.2491</span><span class="p">)</span><span class="o">'</span><span class="p">;</span><span class="c">%red component</span>
<span class="n">g</span><span class="p">=(</span><span class="mf">0.2969</span><span class="p">:(</span><span class="mf">0.4012</span><span class="o">/</span><span class="mi">50</span><span class="p">):</span><span class="mf">0.6981</span><span class="p">)</span><span class="o">'</span><span class="p">;</span><span class="c">%green component</span>
<span class="n">b</span><span class="p">=(</span><span class="mf">0.0625</span><span class="p">:(</span><span class="mf">0.2696</span><span class="o">/</span><span class="mi">50</span><span class="p">):</span><span class="mf">0.3321</span><span class="p">)</span><span class="o">'</span><span class="p">;</span><span class="c">%blue component</span>
<span class="n">map</span><span class="p">=[</span><span class="n">r</span><span class="p">,</span><span class="n">g</span><span class="p">,</span><span class="n">b</span><span class="p">];</span><span class="c">%join in a map</span>
<span class="k">for</span> <span class="n">cnt</span><span class="p">=</span><span class="mi">1</span><span class="p">:</span><span class="mi">6</span>
<span class="c">%change the lower part to brown for the trunk</span>
<span class="n">map</span><span class="p">(</span><span class="n">cnt</span><span class="p">,:)=[</span><span class="mi">77</span><span class="p">,</span><span class="mi">63</span><span class="p">,</span><span class="mi">5</span><span class="p">]</span><span class="o">/</span><span class="mi">265</span><span class="p">;</span>
<span class="k">end</span>
<span class="n">colormap</span><span class="p">(</span><span class="n">map</span><span class="p">)</span><span class="c">%set the map</span>
<span class="n">view</span><span class="p">([</span><span class="o">-</span><span class="mf">37.5</span><span class="p">,</span><span class="mi">4</span><span class="p">])</span><span class="c">%Change the view to see a little more of the Actual 3D tree</span>
<span class="n">lighting</span> <span class="n">phong</span> <span class="c">%some nice lighting</span>
<span class="n">shading</span> <span class="n">interp</span> <span class="c">%remove grid and smoothen the surface color</span>
<span class="n">axis</span> <span class="n">equal</span> <span class="c">%takes care of display in the right proportion</span>
<span class="n">axis</span><span class="p">([</span><span class="o">-</span><span class="mi">10</span> <span class="mi">10</span> <span class="o">-</span><span class="mi">10</span> <span class="mi">10</span> <span class="mi">0</span> <span class="mi">30</span><span class="p">])</span> <span class="c">%give some more axis space (for the snow later)</span>
<span class="n">axis</span> <span class="n">off</span> <span class="c">%but don't show axis</span>
<span class="n">hold</span> <span class="n">on</span> <span class="c">%to draw the rest</span>
<span class="n">title</span><span class="p">(</span><span class="s">'Merry Christmas 知乎er'</span><span class="p">)</span><span class="c">%self explaining</span>
<span class="c">%% Presents</span>
<span class="c">%Draw some presents around the tree (each with random color)</span>
<span class="n">drawPresent</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="o">-</span><span class="mi">4</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">2</span><span class="p">);</span>
<span class="n">drawPresent</span><span class="p">(</span><span class="o">-</span><span class="mi">4</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mf">1.5</span><span class="p">);</span>
<span class="n">drawPresent</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">4</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">3</span><span class="p">);</span>
<span class="n">drawPresent</span><span class="p">(</span><span class="o">-</span><span class="mi">14</span><span class="p">,</span><span class="o">-</span><span class="mi">5</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">6</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">1</span><span class="p">);</span>
<span class="n">drawPresent</span><span class="p">(</span><span class="o">-</span><span class="mi">9</span><span class="p">,</span><span class="o">-</span><span class="mi">10</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">2</span><span class="p">);</span>
<span class="n">drawPresent</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">4</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">4</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">3</span><span class="p">);</span>
<span class="n">drawPresent</span><span class="p">(</span><span class="o">-</span><span class="mi">6</span><span class="p">,</span><span class="o">-</span><span class="mi">13</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">3</span><span class="p">);</span>
<span class="c">%% Snow</span>
<span class="c">%create some random 3D coordinates for the snow (amount as in setup above)</span>
<span class="n">snowX</span><span class="p">=(</span><span class="nb">rand</span><span class="p">(</span><span class="n">snow</span><span class="p">,</span><span class="mi">1</span><span class="p">)</span><span class="o">*</span><span class="mi">25</span><span class="o">-</span><span class="mf">12.5</span><span class="p">);</span>
<span class="n">snowY</span><span class="p">=(</span><span class="nb">rand</span><span class="p">(</span><span class="n">snow</span><span class="p">,</span><span class="mi">1</span><span class="p">)</span><span class="o">*</span><span class="mi">25</span><span class="o">-</span><span class="mf">12.5</span><span class="p">);</span>
<span class="n">snowZ</span><span class="p">=(</span><span class="nb">rand</span><span class="p">(</span><span class="n">snow</span><span class="p">,</span><span class="mi">1</span><span class="p">)</span><span class="o">*</span><span class="mi">27</span><span class="p">);</span>
<span class="c">%Note:Some flakes will end up IN the tree but just can't be seen then</span>
<span class="n">plot3</span><span class="p">(</span><span class="n">snowX</span><span class="p">,</span><span class="n">snowY</span><span class="p">,</span><span class="n">snowZ</span><span class="p">,</span><span class="s">'w*'</span><span class="p">)</span><span class="c">%plot coordinates as white snow flakes</span>
<span class="n">hold</span> <span class="n">off</span><span class="c">%Done</span>
<span class="k">end</span> <span class="c">% of function</span>

<span class="c">%% ============= private functions</span>
<span class="k">function</span><span class="w"> </span>r<span class="p">=</span><span class="nf">tree</span><span class="p">(</span>h<span class="p">)</span><span class="c">%Gives a profile for the tree</span>
<span class="k">for</span> <span class="n">cnt</span><span class="p">=</span><span class="mi">1</span><span class="p">:</span><span class="nb">length</span><span class="p">(</span><span class="n">h</span><span class="p">)</span>

<span class="k">if</span><span class="p">(</span><span class="n">h</span><span class="p">(</span><span class="n">cnt</span><span class="p">)</span><span class="o">==</span><span class="mi">0</span><span class="p">)</span><span class="c">%no Width at the bottom. Ensures a "closed" trunk</span>
<span class="n">r</span><span class="p">(</span><span class="n">cnt</span><span class="p">)=</span><span class="mi">0</span><span class="p">;</span>
<span class="k">end</span>
<span class="c">%smaller radius for the trunk</span>
<span class="k">if</span> <span class="p">(</span><span class="n">h</span><span class="p">(</span><span class="n">cnt</span><span class="p">)</span><span class="o">></span><span class="mi">0</span> <span class="o">&&</span> <span class="n">h</span><span class="p">(</span><span class="n">cnt</span><span class="p">)</span><span class="o"><</span><span class="p">=</span><span class="mi">3</span><span class="p">)</span>
<span class="n">r</span><span class="p">(</span><span class="n">cnt</span><span class="p">)=</span><span class="mf">1.5</span><span class="p">;</span>
<span class="k">end</span>
<span class="c">%reduce radius gradually from 8 to 0. Note: will only work with a trunk heigth</span>
<span class="c">%of 3 and a whole tree heigth of 25. Scale the height of the tree in</span>
<span class="c">%the "draw tree" section, since the cylinder command will return a 1</span>
<span class="c">%unit high cylinder anyway</span>
<span class="k">if</span><span class="p">(</span><span class="n">h</span><span class="p">(</span><span class="n">cnt</span><span class="p">)</span><span class="o">></span><span class="mi">3</span><span class="p">)</span>
<span class="n">r</span><span class="p">(</span><span class="n">cnt</span><span class="p">)=</span><span class="mi">8</span><span class="o">-</span><span class="p">(</span><span class="n">h</span><span class="p">(</span><span class="n">cnt</span><span class="p">)</span><span class="o">-</span><span class="mi">3</span><span class="p">)</span><span class="o">*</span><span class="mf">0.3636</span><span class="p">;</span>
<span class="k">end</span>
<span class="k">end</span>
<span class="k">end</span> <span class="c">% of function</span>
<span class="c">%Draws a present with the given coordinate + size in a random color</span>
<span class="c">%Note:Given coordinates apply to the lower front + left corner of the</span>
<span class="c">%present (the one closest to the viewer) as seen in the plot</span>
<span class="k">function</span><span class="w"> </span><span class="nf">drawPresent</span><span class="p">(</span>dx,dy,dz,scalex,scaley,scalez<span class="p">)</span><span class="w"></span>
<span class="c">%the standard present coordinates</span>
<span class="n">presentX</span><span class="p">=[</span><span class="mf">0.5</span> <span class="mf">0.5</span> <span class="mf">0.5</span> <span class="mf">0.5</span> <span class="mf">0.5</span><span class="p">;</span> <span class="mi">0</span> <span class="mi">1</span> <span class="mi">1</span> <span class="mi">0</span> <span class="mi">0</span><span class="p">;</span> <span class="mi">0</span> <span class="mi">1</span> <span class="mi">1</span> <span class="mi">0</span> <span class="mi">0</span><span class="p">;</span> <span class="mi">0</span> <span class="mi">1</span> <span class="mi">1</span> <span class="mi">0</span> <span class="mi">0</span><span class="p">;</span> <span class="mf">0.5</span> <span class="mf">0.5</span> <span class="mf">0.5</span> <span class="mf">0.5</span> <span class="mf">0.5</span><span class="p">];</span>
<span class="n">presentY</span><span class="p">=[</span><span class="mf">0.5</span> <span class="mf">0.5</span> <span class="mf">0.5</span> <span class="mf">0.5</span> <span class="mf">0.5</span><span class="p">;</span> <span class="mi">0</span> <span class="mi">0</span> <span class="mi">1</span> <span class="mi">1</span> <span class="mi">0</span><span class="p">;</span> <span class="mi">0</span> <span class="mi">0</span> <span class="mi">1</span> <span class="mi">1</span> <span class="mi">0</span><span class="p">;</span> <span class="mi">0</span> <span class="mi">0</span> <span class="mi">1</span> <span class="mi">1</span> <span class="mi">0</span><span class="p">;</span> <span class="mf">0.5</span> <span class="mf">0.5</span> <span class="mf">0.5</span> <span class="mf">0.5</span> <span class="mf">0.5</span><span class="p">];</span>
<span class="n">presentZ</span><span class="p">=[</span><span class="mi">0</span> <span class="mi">0</span> <span class="mi">0</span> <span class="mi">0</span> <span class="mi">0</span><span class="p">;</span> <span class="mi">0</span> <span class="mi">0</span> <span class="mi">0</span> <span class="mi">0</span> <span class="mi">0</span><span class="p">;</span> <span class="mf">0.5</span> <span class="mf">0.5</span> <span class="mf">0.5</span> <span class="mf">0.5</span> <span class="mf">0.5</span><span class="p">;</span> <span class="mi">1</span> <span class="mi">1</span> <span class="mi">1</span> <span class="mi">1</span> <span class="mi">1</span><span class="p">;</span> <span class="mi">1</span> <span class="mi">1</span> <span class="mi">1</span> <span class="mi">1</span> <span class="mi">1</span><span class="p">];</span>
<span class="c">%draw some presents with random colors</span>
<span class="c">%scale present and move it to the right place and get the plot handle</span>
<span class="n">myHandle</span><span class="p">=</span><span class="n">surf</span><span class="p">((</span><span class="n">presentX</span><span class="o">*</span><span class="n">scalex</span><span class="o">+</span><span class="n">dx</span><span class="p">),(</span><span class="n">presentY</span><span class="o">*</span><span class="n">scaley</span><span class="o">+</span><span class="n">dy</span><span class="p">),</span> <span class="p">(</span><span class="n">presentZ</span><span class="o">*</span><span class="n">scalez</span><span class="o">+</span><span class="n">dz</span><span class="p">));</span>
<span class="c">%some random color map</span>
<span class="n">randColorMap</span><span class="p">(:,:,</span><span class="mi">1</span><span class="p">)=</span><span class="nb">repmat</span><span class="p">(</span><span class="nb">rand</span><span class="p">,[</span><span class="mi">5</span><span class="p">,</span><span class="mi">5</span><span class="p">]);</span><span class="c">%r component</span>
<span class="n">randColorMap</span><span class="p">(:,:,</span><span class="mi">2</span><span class="p">)=</span><span class="nb">repmat</span><span class="p">(</span><span class="nb">rand</span><span class="p">,[</span><span class="mi">5</span><span class="p">,</span><span class="mi">5</span><span class="p">]);</span><span class="c">%g component</span>
<span class="n">randColorMap</span><span class="p">(:,:,</span><span class="mi">3</span><span class="p">)=</span><span class="nb">repmat</span><span class="p">(</span><span class="nb">rand</span><span class="p">,[</span><span class="mi">5</span><span class="p">,</span><span class="mi">5</span><span class="p">]);</span><span class="c">%b component</span>
<span class="c">%Assign colormap just to the plot handle object of the present, so the tree</span>
<span class="c">%does not change color</span>
<span class="n">set</span><span class="p">(</span><span class="n">myHandle</span><span class="p">,</span><span class="s">'CData'</span><span class="p">,</span><span class="n">randColorMap</span><span class="p">)</span>
<span class="n">shading</span> <span class="n">interp</span> <span class="c">%Nice shding + without grid</span>
<span class="k">end</span> <span class="c">% of function</span>
로그인 후 복사
Christmas Tree
R语言 能画,但是这种比较有什么意义呢..................................

如何用数学软件画一个“圣诞树”?
<span class="go">L <-  matrix(</span>
<span class="go">    c(0.03,  0,     0  ,  0.1,</span>
<span class="go">        0.85,  0.00,  0.00, 0.85,</span>
<span class="go">        0.8,   0.00,  0.00, 0.8,</span>
<span class="go">        0.2,  -0.08,  0.15, 0.22,</span>
<span class="go">        -0.2,   0.08,  0.15, 0.22,</span>
<span class="go">        0.25, -0.1,   0.12, 0.25,</span>
<span class="go">        -0.2,   0.1,   0.12, 0.2),</span>
<span class="go">    nrow=4)</span>
<span class="go"># ... and each row is a translation vector</span>
<span class="go">B <- matrix(</span>
<span class="go">    c(0, 0,</span>
<span class="go">        0, 1.5,</span>
<span class="go">        0, 1.5,</span>
<span class="go">        0, 0.85,</span>
<span class="go">        0, 0.85,</span>
<span class="go">        0, 0.3,</span>
<span class="go">        0, 0.4),</span>
<span class="go">    nrow=2)</span>

<span class="go">prob = c(0.02, 0.6,.08, 0.07, 0.07, 0.07, 0.07)</span>

<span class="go"># Iterate the discrete stochastic map </span>
<span class="go">N = 1e5 #5  #   number of iterations </span>
<span class="go">x = matrix(NA,nrow=2,ncol=N)</span>
<span class="go">x[,1] = c(0,2)   # initial point</span>
<span class="go">k <- sample(1:7,N,prob,replace=TRUE) # values 1-7 </span>

<span class="go">for (i in 2:N) </span>
<span class="go">  x[,i] = crossprod(matrix(L[,k[i]],nrow=2),x[,i-1]) + B[,k[i]] # iterate </span>

<span class="go"># Plot the iteration history </span>
<span class="go">png('card.png')</span>
<span class="go">par(bg='darkblue',mar=rep(0,4))    </span>
<span class="go">plot(x=x[1,],y=x[2,],</span>
<span class="go">    col=grep('green',colors(),value=TRUE),</span>
<span class="go">    axes=FALSE,</span>
<span class="go">    cex=.1,</span>
<span class="go">    xlab='',</span>
<span class="go">    ylab='' )#,pch='.')</span>

<span class="go">bals <- sample(N,20)</span>
<span class="go">points(x=x[1,bals],y=x[2,bals]-.1,</span>
<span class="go">    col=c('red','blue','yellow','orange'),</span>
<span class="go">    cex=2,</span>
<span class="go">    pch=19</span>
<span class="go">)</span>
<span class="go">text(x=-.7,y=8,</span>
<span class="go">    labels='Merry',</span>
<span class="go">    adj=c(.5,.5),</span>
<span class="go">    srt=45,</span>
<span class="go">    vfont=c('script','plain'),</span>
<span class="go">    cex=3,</span>
<span class="go">    col='gold'</span>
<span class="go">)</span>
<span class="go">text(x=0.7,y=8,</span>
<span class="go">    labels='Christmas',</span>
<span class="go">    adj=c(.5,.5),</span>
<span class="go">    srt=-45,</span>
<span class="go">    vfont=c('script','plain'),</span>
<span class="go">    cex=3,</span>
<span class="go">    col='gold'</span>
<span class="go">)</span>
<span class="go">dev.off()</span>
로그인 후 복사
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

AI Hentai Generator

AI Hentai Generator

AI Hentai를 무료로 생성하십시오.

뜨거운 도구

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전

SublimeText3 중국어 버전

중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)

HTML을 구문 분석하기 위해 아름다운 수프를 어떻게 사용합니까? HTML을 구문 분석하기 위해 아름다운 수프를 어떻게 사용합니까? Mar 10, 2025 pm 06:54 PM

이 기사에서는 HTML을 구문 분석하기 위해 파이썬 라이브러리 인 아름다운 수프를 사용하는 방법을 설명합니다. 데이터 추출, 다양한 HTML 구조 및 오류 처리 및 대안 (SEL과 같은 Find (), find_all (), select () 및 get_text ()와 같은 일반적인 방법을 자세히 설명합니다.

파이썬의 수학 모듈 : 통계 파이썬의 수학 모듈 : 통계 Mar 09, 2025 am 11:40 AM

Python의 통계 모듈은 강력한 데이터 통계 분석 기능을 제공하여 생물 통계 및 비즈니스 분석과 같은 데이터의 전반적인 특성을 빠르게 이해할 수 있도록 도와줍니다. 데이터 포인트를 하나씩 보는 대신 평균 또는 분산과 같은 통계를보고 무시할 수있는 원래 데이터에서 트렌드와 기능을 발견하고 대형 데이터 세트를보다 쉽고 효과적으로 비교하십시오. 이 튜토리얼은 평균을 계산하고 데이터 세트의 분산 정도를 측정하는 방법을 설명합니다. 달리 명시되지 않는 한,이 모듈의 모든 함수는 단순히 평균을 합산하는 대신 평균 () 함수의 계산을 지원합니다. 부동 소수점 번호도 사용할 수 있습니다. 무작위로 가져옵니다 수입 통계 Fracti에서

파이썬 객체의 직렬화 및 사제화 : 1 부 파이썬 객체의 직렬화 및 사제화 : 1 부 Mar 08, 2025 am 09:39 AM

파이썬 객체의 직렬화 및 사막화는 사소한 프로그램의 주요 측면입니다. 무언가를 Python 파일에 저장하면 구성 파일을 읽거나 HTTP 요청에 응답하는 경우 객체 직렬화 및 사태화를 수행합니다. 어떤 의미에서, 직렬화와 사제화는 세계에서 가장 지루한 것들입니다. 이 모든 형식과 프로토콜에 대해 누가 걱정합니까? 일부 파이썬 객체를 지속하거나 스트리밍하여 나중에 완전히 검색하려고합니다. 이것은 세상을 개념적 차원에서 볼 수있는 좋은 방법입니다. 그러나 실제 수준에서 선택한 직렬화 체계, 형식 또는 프로토콜은 속도, 보안, 유지 보수 상태 및 프로그램의 기타 측면을 결정할 수 있습니다.

Tensorflow 또는 Pytorch로 딥 러닝을 수행하는 방법은 무엇입니까? Tensorflow 또는 Pytorch로 딥 러닝을 수행하는 방법은 무엇입니까? Mar 10, 2025 pm 06:52 PM

이 기사는 딥 러닝을 위해 텐서 플로와 Pytorch를 비교합니다. 데이터 준비, 모델 구축, 교육, 평가 및 배포와 관련된 단계에 대해 자세히 설명합니다. 프레임 워크, 특히 계산 포도와 관련하여 주요 차이점

인기있는 파이썬 라이브러리와 그 용도는 무엇입니까? 인기있는 파이썬 라이브러리와 그 용도는 무엇입니까? Mar 21, 2025 pm 06:46 PM

이 기사는 Numpy, Pandas, Matplotlib, Scikit-Learn, Tensorflow, Django, Flask 및 요청과 같은 인기있는 Python 라이브러리에 대해 설명하고 과학 컴퓨팅, 데이터 분석, 시각화, 기계 학습, 웹 개발 및 H에서의 사용에 대해 자세히 설명합니다.

아름다운 수프로 파이썬에서 웹 페이지를 긁어 내기 : 검색 및 DOM 수정 아름다운 수프로 파이썬에서 웹 페이지를 긁어 내기 : 검색 및 DOM 수정 Mar 08, 2025 am 10:36 AM

이 튜토리얼은 간단한 나무 탐색을 넘어서 DOM 조작에 중점을 둔 아름다운 수프에 대한 이전 소개를 바탕으로합니다. HTML 구조를 수정하기위한 효율적인 검색 방법과 기술을 탐색하겠습니다. 일반적인 DOM 검색 방법 중 하나는 EX입니다

Python으로 명령 줄 인터페이스 (CLI)를 만드는 방법은 무엇입니까? Python으로 명령 줄 인터페이스 (CLI)를 만드는 방법은 무엇입니까? Mar 10, 2025 pm 06:48 PM

이 기사는 Python 개발자가 CLIS (Command-Line Interfaces) 구축을 안내합니다. Typer, Click 및 Argparse와 같은 라이브러리를 사용하여 입력/출력 처리를 강조하고 CLI 유용성을 향상시키기 위해 사용자 친화적 인 디자인 패턴을 홍보하는 세부 정보.

파이썬에서 가상 환경의 목적을 설명하십시오. 파이썬에서 가상 환경의 목적을 설명하십시오. Mar 19, 2025 pm 02:27 PM

이 기사는 프로젝트 종속성 관리 및 충돌을 피하는 데 중점을 둔 Python에서 가상 환경의 역할에 대해 설명합니다. 프로젝트 관리 개선 및 종속성 문제를 줄이는 데있어 생성, 활성화 및 이점을 자세히 설명합니다.

See all articles