e^t

我是风的歌

正在浏览标签为 Mathematica 的文章

I don’t know how many of you were frustrated by the default font size of Mathematica, especially when there seems to be no way to change it!

But you no longer have to — here is the way (Version 8.0):

Go to: “Format”->”Option Inspector…” (or Shift + Ctrl + O)

A compound dialog pops up, to change font size just expand “Formatting Options”,

click on “Font Options” item, and change whatever you want in the right panel!

There are lots of additional options to hack with, cheers~

NOTE: first close all your notebooks – otherwise the your settings will automatically change back!

Update:

The above is for MS windows. for Linux things are a little bit different. You need to change the item of the dropdown list named ‘Show Option Values’ to ‘Global Preferences’. See the screenshot below.

Options for Global Preferences

I was asked about this, and here is the most concise code I came up with. Enjoy!

f[x_]:=2Cos[x];
xlist=NestList[f[#]&,0.6,50];ylist=f[xlist];
list=Riffle[Transpose[{xlist,ylist}],Transpose[{Drop[xlist,1],Drop[xlist,1]}]];
iterplot=ListLinePlot[list];funplot=Plot[{x,f[x]},{x,-2,2},PlotRange->{-2,2},PlotStyle->{Black}];Show[{funplot,iterplot}]

Result for f(x) = 2*cos(x):


使用Mathematica产生分形的思路
注:不是本人的思路,是我的一个百度回答
链接:http://zhidao.baidu.com/question/131142900.html
提问者给出的代码如下:
g[l_] := Flatten[
Replace[l, {u_ -> {u, Mod[u - 1, 6], Mod[u + 1, 6], u}}, {1}], 1];
list1 = {0, 2, 4};
ListLinePlot[
Prepend[Accumulate[
Replace[Nest[g, list1, 5], {0 -> {1, Sqrt[3]}, 1 -> {2, 0},
2 -> {1, -Sqrt[3]}, 3 -> {-1, -Sqrt[3]}, 4 -> {-2, 0},
5 -> {-1, Sqrt[3]}}, {1}]], {0, 0}], Axes -> False,
AspectRatio -> Automatic, AxesOrigin -> {0, 0}]
我的解释是:

用来替换的那些都是控制曲线转向的向量。
{0, 0}作为起始点 而{0, 2, 4}作为起始转向,你可以发现如果不替换的话那么这就会画出一个三角形。然后就是怎么替换这些转向使得它们转更多的弯了。例如0所对应的是{1, Sqrt[3]},也就是朝右上方发展的,我们想让它先发展一段然后就朝左上(由5控制)再朝正右方向转(由1控制)最后再沿着右上发展,也就是我们要完成0->{0, 5, 1, 0}的替换。其他类似。
这里的巧妙是不需要一个一个写出来而用Mod的方法,见下图,可以看到方向i需要变成{i, i左边的, i右边的, i},真是这个普遍的相邻关系,我们可以用Mod加以概括。

#end
产生分形的关键是一个用来不断自我替换的rule,只要你有了一个“元变换”,通过这个例子的方法就可以轻易地产生你想要的分形。一个小例子:
g2[l_] :=
Flatten[Replace[
l, {u_ -> {u, Mod[u - 1, 4], u, Mod[u + 1, 4], u}}, {1}], 1];

list2 = {0, 1, 2, 3};

ListLinePlot[
Prepend[Accumulate[
Replace[Nest[g2, list2, 4], {0 -> {1, 0}, 1 -> {0, -1},
2 -> {-1, 0}, 3 -> {0, 1}}, {1}]], {0, 0}],
AspectRatio -> Automatic, AxesOrigin -> {0, 0}]

仿照Koch雪花的,只是用正方形替换中间那1/3的线段,结果如下:

推荐对这些代码进行惨无人道的实验!
不好意思,上次的解释左右不分,已经更正

一个比较疯狂的方法
先让那个球用初速度尽情跑。得到一个直线轨迹之后再按照边界条件不断反射弯曲。这样做的好处是可以尽情使用list。下面的代码还可以优化,但是我得睡会儿觉了……

初始条件和求解参数
v = {0.9, 0.7, 1.5}; p0 = {0, 0, 0}; L = 1; T = 10; dt = 0.1;

直线轨迹
track = NestList[Plus[#, v*dt] &, p0, 100]

反射弯曲轨迹的函数
reflect[tracky_List] :=
Module[{track = tracky, pos = 1, velpos = 1, sign = 1, i},
While[True,
pos = LengthWhile[track,
0 <= #1 <= 1 && 0 <= #2 <= 1 && 0 <= #3 <= 1 &];
If[pos >= Length[track], Break[]];
velpos = Position[trackpos + 1, _?(# > 1 || # < 0 &)]1, 1;
sign = Sign[trackpos + 1, velpos];
For[i = 1, i <= Length[track] – pos, i += 1,
trackpos + i, velpos -= sign*2*vvelpos*dt*i]]; track];

反射后的轨迹
track=reflect[track];

可视化
Manipulate[Show[{
Graphics3D[Sphere[tracki, 0.02]],
Graphics3D[Arrow[track1 ;; i]]},
PlotRange -> {{0, L}, {0, L}, {0, L}}], {i, 1, Length[track], 1}]

Maple,Mathematica,Matlab,软件杂谈

曾经上过几次MapleSoft的网站,总是对上面的Mathematics=Maple这句话耿耿于怀。不过前些日子思维突然一转,于是仿照着写下:

Engineering=MatLAB
Computation=Mathematica
Mathematics=Maple
相当贴切,自我感觉良好哈!

我一直怀疑Mathematica在工程领域到底应用了多少。至少另两位都有(类似)Simulink之类的东东,都在仿真领域下了大工夫,Mathematica却一直不见动静——就连Scilab这个开源软件都搞了一个Scicos啊!可是Mathematica似乎意志坚定了就是要走不同的路,就像Wolfram|Alpha这类产品应该会让Wolfram之外的所有人吃惊吧(当然也包括其Competitors),一个数学软件公司竟然和Google搞上了——至少当时大家都是这样说的。不过再怎么说工程领域也是个大蛋糕啊,工科的学生不管国内国外好像没有谁把Mathematica当成主角的,那些另外收费的Mathematica软件包用了多少了?没有MatLAB的Toolbox多吧。不得不承认Mathematica的MathWorld和Demonstration Project都很有创意,而不管Mathematica在TIOBE排行上面比MatLAB低多少名次,它都会有一群坚定地使用者,可是不在工程领域这个最能赚钱的地方好好努力的话,终究还是会影响软件发展的。

7.0不知道算不算是努力的标志,最大亮点的Image Processing毕竟太Specific了一点。Computable Data倒是蛮好的,但是如果要在工程领域推进的话,完全可以做的更好。例如空白的界面和直线式的显示方式,我认为应该被替换为类似MatLAB那种,可以方便地Check变量列表和相应的值。Wolfram在Mathematica 7.0出来之前还说已经有8.0甚至9.0的idea了,也不知道什么时候可以展示出来。

杂:
还有就是Maple就敢大胆使用13作为版本号,不明白CorelDraw当时为什么还神神鬼鬼地搞一个X3出来,难道艺术家更加感性,无语……

没事又看了看Maple官网上的Demo,那个MapleSim应该是吸取了Simulink和一般的GUI设计软件的各自优点,很好!虽然我不用。

另外Jobs不知道是不是糊涂了,QuickTime的新图标难看的要死。电脑上面唯一一个苹果软件还搞得最没有美感,这和心目中苹果的一贯形象相比,可成了个讽刺啊~

问题链接:

http://zhidao.baidu.com/question/100344570.html?fr=kw&fs=up

问题内容:设有一平面温度场T=100-X^2-4Y^2,一粒子从A(6,4)出发始终沿温度升高最快的方向运动,试用mathematica模拟粒子运动轨迹。

解答:
定义场:
In: T[x_, y_] := 100 – x^2 – 4 y^2;

得到梯度:
In: {D[T[x, y], x], D[T[x, y], y]}
out: {-2 x, -8 y}

形象一点:
conP = ContourPlot[T[x, y], {x, -6, 6}, {y, -6, 6}];
vecP = VectorPlot[{-2 x, -8 y}, {x, -6, 6}, {y, -6, 6}];
Show[{conP, vecP}]



运动方程和初始条件:

eqn = Thread[{D[x[t], {t, 2}],D[y[t], {t, 2}]} == {-2 x[t], -8 y[t]}];
ic = {x[0] == 6, y[0] == 4, x’[0] == 0, y’[0] == 0};

可以求解的方程:
eqnic = Flatten[{eqn, ic}];

数值解:
sol = NDSolve[eqnic, {x, y}, {t, 0, 10}];
可视化:
track = ParametricPlot[Evaluate[{x[t], y[t]} /. sol], {t, 0, 10}];

最终结果:
Show[{conP, vecP, track}]

昨天看到的是大概今天上午11点就可以使用,一忙忘记了。
刚才突然想到就连忙试一试。自己的第一次搜索搜什么呢,当然是Strawberry Panic啦!
结果不出我所料,Wolfram|Alpha不知道我想找什么……

就要午睡了,起来后好好试一试。