星期二, 八月 29, 2006

Cool Tips:Mathematica Notebook 输出文本控制

Mathematica里的文本输出是Print方法。
在Mathematica里,文本的被抽象为text和Form.
标准的对象构造方法为:Text.
Show[Graphics[Text["hi",{10,10}]]]


可以控制字体各种属性的构造方法为: StyleForm
StyleForm["2005 Year",
FontSize -> 24, FontWeight -> "Bold", FontColor ->
RGBColor[1, 0, 0],Background->GrayLevel]];

输出大字:2005 Year

StyleForm是最常用的用来控制艺术文字输出的。
但有时侯需要输出格式化的数学公式之类的,就需要用其他的Form
StyleForm的标准构造如下。
StyleForm[expr, options]
其中expr可以接受表达式的输入。
比如输出一个数学公式,需要用M的函数StandForm来格式化。
values=BesselJ[5,Range[20]];
ListPlot[values, PlotLabel -> StyleForm[
StandardForm[1/x^2],
FontSize -> 24, FontWeight -> "Bold", FontColor -> RGBColor[
1, 0, 0], Background -> GrayLevel[0.5]]]
得到如图:


Graphics有两个Hook方法.Prolog和Epilog分别是在绘画主图前和后调用来产生图形同主图形
透视的函数。
比如想在一个圆点内写上字,就应该如下:
Show[Graphics[{{PointSize[.075], RGBColor[1, 0, 0], Point[{0, 0}]}}], Epilog -> Text["1", {0, 0}, TextStyle -> {FontSize -> 24, FontStyle -> "BOLD", FontColor -> RGBColor[0, 1, 0]}]];

星期一, 八月 28, 2006

Mathimatica 里notebook的环境问题。

为了解决插值问题,简单几个语句,竟然无法得出正确的结果:
data={7,2,3,25,1,10};
f = InterpolatingPolynomial[data, x];
f
f /. x -> 5

得到一个很奇怪的结果。如图。
















经过在组里询问:mathgroup@smc.vnet.net 和GroupGroup.
http://groups.google.com/group/comp.soft-sys.math.mathematica
得到BOB及其他答案,认为是Mathemathica 的kernel不"干净"需要重新启动Mathematica 再看看。
最终。使用bob的方法。
:
data={7,2,3,25,1,10};
Clear[f];
f[x_]=InterpolatingPolynomial[data,x];
f[5]

终于得到正确的答案1

而且最近 被Mathematica的变量的范围问题(Variable Scope)弄的头大,
根据手册,Module和Block申明的变量应该是在外面不可见的。
但输入函数中的变量依然可以被看见,这就导致了,循环调用函数的时候,外部的
For 循环计数器同函数内部的变量冲突了。
Damned

星期六, 八月 26, 2006

Sun有发布两个新的服务网站,很不错

Javascript Development Center.
http://java.sun.com/javascript/

Development Services
http://developers.sun.com/services/

星期五, 八月 25, 2006

如何显示点图和连线图,在Mathematica 5

data = Import["E:/ebook/彩票数据/2006兰色球.txt", "TABLE"];
g1 = ListPlot[data, ImageSize -> {640,
480}, AxesLabel -> {"序号", "兰色球"}, PlotStyle -> {
PointSize[.04], RGBColor[1, 0, 0]}, PlotJoined -> True,
AxesOrigin -> {0, 0}](*好的*);
g2 = ListPlot[data, ImageSize -> {640,
480}, AxesLabel -> {"序号", "兰色球"}, PlotStyle -> {
PointSize[.04], RGBColor[1, 0, 0]}, PlotJoined -> False,
AxesOrigin -> {0, 0}](*好的*);

Show[g1,g2];

星期四, 八月 24, 2006

Mathematica 中的插值(Interpolation)函数及使用

Mathematica 支持所有的数学插值概念,比如拉格朗日(lagrange) 插值,牛顿(newTon)插值.
及其他插值方法。
各种插值方法:http://mathworld.wolfram.com/Interpolation.html
参考数值积分:http://mathworld.wolfram.com/NumericalIntegration.html


使用拉格朗日(lagrange) 插值的函数为InterpolatingPolynomial
参考: http://mathworld.wolfram.com/LagrangeInterpolatingPolynomial.html
最后的结果用Newton-Cotes formula 牛顿-科茨公式形式

NewTon插值没有实现可以参看一个实现:
http://math.fullerton.edu/mathews/n2003/NewtonPolyMod.html
或这里:http://mathworld.wolfram.com/NewtonsDividedDifferenceInterpolationFormula.html



f = Interpolation[lsdata[[All, {3, 4, 5, 6, 7, 8, 9}]][[1]]]
f[4]

NumericalMath`PolynomialFit`
InterpolatingPolynomial[lsdata[[All, {3, 4, 5, 6, 7, 8}]][[1]], x]
N[f /. x -> 3]
(*freeze lock*)
InterpolatingPolynomial[lsdata[[All, {3, 4}]], x]
(*dead*)

星期一, 八月 21, 2006

Mathematica 图形IO接口

打开一个文件选择:
两种方法:
4.0之后,Mathematica 提供函数包 <FileBrowse
选择文件后,返回选择的文件完全路径

比如打开一个Access数据库,需要用户选择文件所在目录
Needs["DatabaseLink`"]
(*DatabaseExplorer[]*)
conn= OpenSQLConnection[JDBC["sun.jdbc.odbc.JdbcOdbcDriver", "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ="<>Experimental`FileBrowse[]], "Name" -> "test",
"Description" -> "", "Username" -> "root", "Password" -> "",
"RelativePath" -> False, "Version" -> 1]

二,使用Java来编写一个跨平台的FileChooser
Needs["JLink`"]

FileChooserDialog[] := FileChooserDialog["Select a file:", "Open", Directory[]]

FileChooserDialog[title_String, okText_String, dir_String] :=
JavaBlock[
Module[{dlg, chosenFile, result = Null},
InstallJava[];
dlg = JavaNew["javax.swing.JFileChooser"];
dlg@setCurrentDirectory[JavaNew["java.io.File", dir]];
dlg@setDialogTitle[title];
If[dlg@showDialog[Null, okText] === JFileChooser`APPROVEUOPTION,
chosenFile = dlg@getSelectedFile[];
If[chosenFile =!= Null,
result = chosenFile@getPath[]
]
];
result
]
]
In[1]:=FileChooserDialog[]
返回选择文件路径。

星期六, 八月 19, 2006

Mathematica 有关微积分的函数包

Calculus`VariationalMethods`

里面包括Euler(?Lagrange) 方程的应用。

看到这里。我想得出 数学模型的建立和 数论之间的关系。

由此得出了,要想把模型建立的纯熟,<<数值分析>>Numerical Analysis的教材是必须要学习的。

所以 下载了一些教材。这里是老外的教材下载.
http://william.wang.googlepages.com/Numerical Analysis.rar

星期一, 八月 14, 2006

金山词霸 2005 XP 不能取词原因

必须保证XP的服务:
DCOM 服务器进程启动器
已经启动。

第二可能同数据执行保护(DEP)有关

微软提供的新功能??数据执行保护(DEP)惹的祸,要出现这个问题,需要满足以下两个条件:
1、系统支持数据执行保护(DEP)功能,目前知道2003sp1支持,估计XP sp2也支持
2、CPU支持硬件DEP,我的AMD Athlon64 2800+就有这个问题,而Athlon 1600+没有,单位的P4 2.66也没有。
(得到的结论就是:Athlon64支持硬件DEP。不支持硬件DEP的在设定DEP的界面有提示,说只能执行软件DEP云云。再给我偏爱的AMD做一次广告!)

解决办法:
我的电脑(鼠标右键)??〉属性??〉高级??〉性能(设置)??〉数据执行保护??〉添加金山词霸的主文件

需要重启系统才能生效

星期六, 八月 12, 2006

Mathematica 数据类型转换

如何把一个数字字符串,转换为数字?

方法:
使用ToExpression [expr]

比如:"33",使用
b=ToExpression["33"]
Head@b执行后得到:
Integer

非常隐秘的方法。

星期五, 八月 11, 2006

Mathematica 中的数据类型判断

如何判断一个变量的数据类型?

两种方法。
1.用Head方法
Head@变量名字.
如同Java InstanceOf,
2.用Q族方法。
NumberQ
NumericQ
IntegerQ
EvenQ
OddQ
PrimeQ;
ArrayQ
VectorQ
MatrixQ (for these there are nice element tests too)
PolynomialQ (element tests). There are built in "structural" tests
SameQ
UnsameQ
OrderedQ
MemberQ
FreeQ
MatchQ
ValueQ
AtomQ

星期四, 八月 10, 2006

Mathematica 快速访问 MS Access数据库

(*注意红色URL写法*)

Needs["DatabaseLink`"]
(*DatabaseExplorer[]*)
conn= OpenSQLConnection[JDBC["sun.jdbc.odbc.JdbcOdbcDriver", "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=D:\lottery\history.mdb"], "Name" -> "test",
"Description" -> "", "Username" -> "root", "Password" -> "",
"RelativePath" -> False, "Version" -> 1]

星期五, 八月 04, 2006

Mathematica 一些表达式语法

1.单值函数调用 用 @ 符号

2.字符串连接用<> 符号. "ddd"<>"bbb" 得到 dddbbb

3.函数返回值。 最后一个表达式的结果 默认为函数的结果。