|
|
|
|
|
|
发新文章 |
|
|
2013年5月19日
相关链接
http://www.matrix67.com/blog/archives/500
http://www.cnblogs.com/zhuangzhuang1988/archive/2013/01/03/2843491.html
http://hyry.dip.jp:8000/pydoc/fractal_chaos.html#ifs
http://blog.csdn.net/waynebuaa/article/details/2762977

Mathematica code:
arr = {{{{0.85, 0.04}, {-0.04, 0.85}}, {0, 1.6}},
{{{0.2, -0.26}, {0.23, 0.22}}, {0, 1.6}},
{{{-0.15, 0.28}, {0.26, 0.24}}, {0, 0.44}},
{{{0, 0}, {0, 0.16}}, {0, 0}}};
iter[p_] := #.p + #2 & @@ RandomChoice[{0.85, 0.07, 0.07, 0.01} -> arr]
Graphics[{Green, PointSize@.001, Point@NestList[iter, N@{0, 0}, 5 10^5]}]
可读性可能更好的版本:
A[1] = {{0.85, 0.04}, {-0.04, 0.85}};
A[2] = {{0.2, -0.26}, {0.23, 0.22}};
A[3] = {{-0.15, 0.28}, {0.26, 0.24}};
A[4] = {{0, 0}, {0, 0.16}};
B[1] = {0, 1.6};
B[2] = {0, 1.6};
B[3] = {0, 0.44};
B[4] = {0, 0};
iter[p_] := With[{x = RandomChoice[{0.85, 0.07, 0.07, 0.01} -> {1, 2, 3, 4}]}, A[x].p + B[x]]
Graphics[{Green, Point@NestList[iter, {0, 0}, 10^4]}]
posted @ 2013-05-19 21:57 chyanog 阅读(6) 评论(0) 编辑
2013年3月23日
stackverflow上看到一个php版的,
$x = 200;
$y = 200;
$gd = imagecreatetruecolor($x, $y);
$corners[0] = array('x' => 100, 'y' => 10);
$corners[1] = array('x' => 0, 'y' => 190);
$corners[2] = array('x' => 200, 'y' => 190);
$red = imagecolorallocate($gd, 255, 0, 0);
for ($i = 0; $i < 100000; $i++) {
imagesetpixel($gd, round($x),round($y), $red);
$a = rand(0, 2);
$x = ($x + $corners[$a]['x']) / 2;
$y = ($y + $corners[$a]['y']) / 2;
}
header('Content-Type: image/png');
imagepng($gd);
用Mathematica画画
version1
a[0] = {x -> 100, y -> 10};
a[1] = {x -> 0, y -> 190};
a[2] = {x -> 200, y -> 190};
m = 200;
n = 200;
pts = Table[r = RandomInteger[{0, 2}];
m = (m + x /. a[r])/2;
n = (n + y /. a[r])/2; {m, n}, {1000}];
Graphics[Point@-pts]
version 2
a = N@{{100, 10}, {0, 190}, {200, 190}};
{m, n} = {200, 200};
pts = Table[{r1, r2} = RandomChoice[a];
{m, n} = {(m + r1)/2, (n + r2)/2}, {1000}];
Graphics[Point@-pts]
version 3
ListPlot@NestList[(# + RandomChoice[{{0, 0}, {1, 0}, {.5, .8}}])/ 2 &, {0., 0.}, 10^3]

很容易推广到空间中
With[{v = {{0, 0, 0.6}, {-0.3, -0.5, -0.2},
{-0.3, 0.5, -0.2}, {0.6, 0, -0.2}}},
ListPointPlot3D[
NestList[(# + RandomChoice[v])/2 &, {0., 0., 0}, 2 10^4],
BoxRatios -> 1, ColorFunction -> "Pastel"]]

posted @ 2013-03-23 23:00 chyanog 阅读(18) 评论(0) 编辑
2012年11月30日

http://www.wolfram.com/mathematica/new-in-9/
The new Wolfram Predictive Interface, which dramatically improves navigation and discovery of Mathematica's functionality
Highly integrated units support, including free-form linguistic entry, conversions , and dimensional consistency checking across graphics and numeric and symbolic calculations
New graph and network analysis, including a built-in link for Facebook, LinkedIn , Twitter, and more
Direct CDF deployment with live data at runtime and other enhanced features with Mathematica Enterprise Edition, plus preview modes that emulate Wolfram CDF Player and Wolfram Player Pro
Major new data science, probability, and statistics functionality—including survival and reliability analysis, Markov chains, queueing theory, time series, and stochastic differential equations
3D volumetric image processing and out-of-core technology that scales up performance to very large 2D and 3D images and video Integrated analog and digital signal processing
Built-in symbolic tensors with support for arrays of any rank, dimension, and symmetry Highly customizable interactive gauges for dashboards and controls
Systemwide support for automatic legends for plots and charts R fully integrated into Mathematica workflow for seamless data and code exchange
Full client-side web access for exchanging data with remote servers and interacting with web APIs Updated look for slide shows with new style templates and background images
posted @ 2012-11-30 15:01 chyanog 阅读(1289) 评论(0) 编辑
2012年11月21日



Mathematica code:
coords =1/2{{1,-(Sqrt[3]/3)},{0,(2Sqrt[3])/3},{-1,-(Sqrt[3]/3)}};
colors ={Red,Green,Blue}; Fold[ImageAdd,First@#,Rest@#]&@ MapThread[Graphics[{##},PlotRange->1.8,Background->Black]&, {colors,Disk/@ coords}] Clear[coord, colors]
Manipulate[
With[{c1 ={x1, y1}, c2 ={x2, y2}, c3 ={x3, y3}},
Module[{pts1, pts2, pts3},
{pts1, pts2, pts3}=
Quiet@Solve[{Tr[({x, y}-#1)^2]==#2^2,
Tr[({x, y}-#3)^2]==#4^2},{x, y},Reals]&@@@{{c1, r1,
c2, r2},{c1, r1, c3, r3},{c2, r2, c3, r3}};
Fold[ImageAdd,First@#,Rest@#]&@
MapThread[
Graphics[{##,{PointSize[Large],
Point[If[#=={},{},{x, y}/.#//Re]]&/@{pts1, pts2,
pts3}}}, Axes->1,AxesStyle->White,PlotRange->6,
Background->GrayLevel[0.02]]&,{{Red,Green,Blue},
Disk@@@{{c1, r1},{c2, r2},{c3, r3}}}]]],
{{x1,1},-4, 4},{{y1,-1/Sqrt[3]},-4,4},{{r1,2},0,4},
{{x2,0},-4,4},{{y2,2/Sqrt[3]},-4,4},{{r2,2},0,4},
{{x3,-1},-4, 4},{{y3,-1/Sqrt[3]},-4,4},{{r3,2},0,4}]
posted @ 2012-11-21 21:34 chyanog 阅读(37) 评论(1) 编辑
2012年9月22日
def matrixMul(A, B):
res = [[0] * len(B[0]) for i in range(len(A))]
for i in range(len(A)):
for j in range(len(B[0])):
for k in range(len(B)):
res[i][j] += A[i][k] * B[k][j]
return res
def matrixMul2(A, B):
return [[sum(a * b for a, b in zip(a, b)) for b in zip(*B)] for a in A]
a = [[1,2], [3,4], [5,6], [7,8]]
b = [[1,2,3,4], [5,6,7,8]]
print matrixMul(a,b)
print matrixMul(b,a)
print "-"*90
print matrixMul2(a,b)
print matrixMul2(b,a)
print "-"*90
from numpy import dot
print map(list,dot(a,b))
print map(list,dot(b,a))
#Out:
#[[11, 14, 17, 20], [23, 30, 37, 44], [35, 46, 57, 68], [47, 62, 77, 92]]
#[[50, 60], [114, 140]]
#------------------------------------------------------------------------------------------
#[[11, 14, 17, 20], [23, 30, 37, 44], [35, 46, 57, 68], [47, 62, 77, 92]]
#[[50, 60], [114, 140]]
#------------------------------------------------------------------------------------------
#[[11, 14, 17, 20], [23, 30, 37, 44], [35, 46, 57, 68], [47, 62, 77, 92]]
#[[50, 60], [114, 140]]
posted @ 2012-09-22 19:37 chyanog 阅读(482) 评论(0) 编辑
2012年9月21日
摘要: list 是 Python 中使用最频繁的数据类型, 标准库里面有丰富的函数可以使用。不过,如果把多维列表转换成一维列表(不知道这种需求多不多),还真不容易找到好用的函数,要知道Ruby、Mathematica、Groovy中可是有flatten的啊。如果列表是维度少的、规则的,还算好办例如:li=[[1,2],[3,4],[5,6]]print [j for i in li for j in i]#orfrom itertools import chainprint list(chain(*li))#ora=[[1,2],[3,4],[5,6]]t=[][t.extend(i) for i 阅读全文
posted @ 2012-09-21 12:22 chyanog 阅读(1331) 评论(5) 编辑
2012年9月16日
摘要: 递归:def J(n,x): return 0 if n==1 else (J(n-1,x)+x-1) % n循环:def J(n,x): k=0 for i in range(2,n+1): k=(k+x)%i return k+1列表推倒:def J(n,x): return reduce(lambda t, _: (t[(x-1) % len(t):] + t[:(x-1) % len(t)])[1:], range(n-1), range(1, n+1))def J(n,x): li=range(1,n+1) while li: ... 阅读全文
posted @ 2012-09-16 20:55 chyanog 阅读(42) 评论(0) 编辑
2012年9月15日
摘要: mathics是一个开源、免费、通用、跨平台的计算机代数系统(CAS),语法、函数和Mathematica几乎完全一致。它使用Python开发,依赖于Sympy(python的符号计算库)、mpath、gmpy等,并且可以借助Sagemath获得更强的能力。类似于Sage,mathics也有在线版本,可以通过浏览器进行各种运算。主页:http://www.mathics.org/下面简要谈下windows系统下的安装,首先需要安装Python(建议python2.7.3, 我不确定3.x系列是否可以),解压从官网下载下来的mathics-0.5.zip,目录中包含一个setup.py文件,在该 阅读全文
posted @ 2012-09-15 01:10 chyanog 阅读(1016) 评论(2) 编辑
2012年9月12日
摘要: 1 #include <stdio.h> 2 #include <time.h> 3 4 int power(int a, int n) 5 { 6 int t = 1; 7 while (n != 0) 8 { 9 if ((n & 1) == 1)10 t = t * a;11 a = a * a;12 n = n >> 1;13 }14 return t;15 }16 17 void func(int x, int N) 18 {19 static int a[10... 阅读全文
posted @ 2012-09-12 23:51 chyanog 阅读(204) 评论(1) 编辑
2012年8月25日
摘要: 1 import xlwt 2 3 wbk=xlwt.Workbook() 4 sheet1=wbk.add_sheet("my_sheet1") 5 6 for i in range(1,10): 7 for j in range(1,i+1): 8 sheet1.write(i-1,j-1,"%sx%s=%s"%(j,i,j*i)) 9 10 wbk.save("C:/test.xls")11 print "Done!"12 13 '''14 for i in range(1,10):1 阅读全文
posted @ 2012-08-25 15:51 chyanog 阅读(185) 评论(0) 编辑
|
|