声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 2542|回复: 3

[工具箱] matlab符号工具箱学习笔记

[复制链接]
发表于 2008-7-30 20:04 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
这里的是底层代码的解释和一些细节问题,有些人并不需要看,所以可以忽略呢.字数超过了论坛限制,其余部分在附件里面符号工具箱里面使用了很多 字符串的 构造方式, 这是非常的值得学习的构造技巧
而这里主要是讲解符号工具箱的char函数,mhelp函数,maple函数,map函数,findstr函数,findsym函数,setstr,lower,sort,strrep函数等等,因为没有时间整理会很乱,当然有心的人应该可以看到想看的东西.
本人曾经比较熟练maplematlab的符号计算工具箱,但由于使用比较少,而未进行进一步的整理,我有时间的话,会作出一个更好的版本出来.

该问主要使用matlab符号工具箱,本身自带的函数,以及其内部代码来学习,
如果你看到源代码,大部分来自于help 或者是 open char, 也就是char的源代码,或者其它函数的源代码,比如 findstr的源代码等等
maple traceon % or maple trace on
这句话很重要,如果你熟悉maple的语法的话,是个不错的选择
当然在符号计算方面我觉得maplematlab要强悍许多,唯一不爽的就是矩阵的输入在maple里面比较的烦,而且要用到比较令人厌烦的Matrix以及map等等,
但是它的表示方式更加人性化,功能当然也是更加的强大.

这可以互相借鉴和比较.
此外还涉及到 int的源代码解释等
还给出了一个基本的函数列表,没有参数解释

此外还要提醒大家注意的是
matlab里面的company
compan的那个函数,其实 应该是友矩阵, 而不能叫做伴随矩阵
伴随矩阵的英文是 adjoint matrix
所以要求伴随矩阵 ,应该用 maple adjoint 函数来实现
不知道是谁翻译错了,大家一错再错,我看的多本matlab的书里面都是这样子的,这真是一个问题



函数列表ndims
得到矩阵的维数
char 把符号变量变成 char,
有一维 二维 三维及以上的区分
numel(S,2,1:3)
得到元素个数
cumprod
char 函数中用到了这个函数(使用type char 或者 open char 可以看到这个 cumprod)
而且在char中用到
printf
函数
应该是sprintf 格式化字符串输出
z =[12]
Mbegin = ['array(' sprintf('1..%d,',z) '[']
还用到了
cell函数
cell 将会用到 {}

syms x y z x1 y1 z1
S = [ x y z ;
x1 y1 x;
]
S = repmat(S,2,3)
S=reshape(S,2,2,9)
char(S)
将会得到
array(1..2,1..2,1..9,[(1,1,1)=x,(2,1,1)=x1,(1,2,1)=x,(2,2,1)=x1,(1,1,2)=y,(2,1,2)=y1,(1,2,2)=y,(2,2,2)=y1,(1,1,3)=12,(2,1,3)=x,(1,2,3)=12,(2,2,3)=x,(1,1,4)=x,(2,1,4)=x1,(1,2,4)=x,(2,2,4)=x1,(1,1,5)=y,(2,1,5)=y1,(1,2,5)=y,(2,2,5)=y1,(1,1,6)=12,(2,1,6)=x,(1,2,6)=12,(2,2,6)=x,(1,1,7)=x,(2,1,7)=x1,(1,2,7)=x,(2,2,7)=x1,(1,1,8)=y,(2,1,8)=y1,(1,2,8)=y,(2,2,8)=y1,(1,1,9)=12,(2,1,9)=x,(1,2,9)=12,(2,2,9)=x])
这样的一个形式
int函数

r = reshape(maple(
'map','int',f(:),x),size(f));
这一句有个重要的语法,
就是f(:),把这个f里面的,也就是元素 全部而展开成一列,然后积分,
矩阵向量化
然后在 reshape , size函数
向量矩阵化

此外还有 map int
syms x y z
s =[ x y z;x y z]
maple('map','int',s(:),x)
会得到
ans =


1/2*x^2


1/2*x^2


y*x


y*x


z*x


z*x

reshape(ans,size(s))
ans =

[ 1/2*x^2,
y*x,
z*x]

[ 1/2*x^2,
y*x,
z*x]

这便是 结果了
如何把一个矩阵的运算编程一个个标量函数的运算,
然后再 重新排列成矩阵
符号变量应该是一个结构
比如s.s将会得到 x y z …
syms b
b = sym(b)
b.s
结构的字符串

r = reshape(maple(
'map','int',f(:),[x.s '=(' a.s ')..(' b.s ')']),size(f));
这句可以看出来了, 有这个
a.s
b.s
这时候 返回一个字符串,
[ab] 的图案可以表示出来
[x.s '=(' a.s ')..(' b.s ')']
这句实际上会得到这样一个句子
x = a..b
J
也就是maple的语法,
传给maple的都是字符串
注意在调试的语法中是 原来工作空间的 变量将 不可以再访问,尤其当文件切换到 其它的调用函数的时候
class(S)
将返回sym
是字符串的
B = maple('transpose',A);
maple有两种调用方法
1.
是用这种 函数带引号, 对象 sym
2.
使用 maple 后面是整个字符串,完全用maple的语法
maple('traceon')
中间没有空格的哦
J
maple('traceon')
syms x y z
A= [ x y ;
z z]
int(A,x)

是个很好的调用maple 并且观察内部运作的方法

int(A,x)

statement:

map(int,vector([x,z,y,z]),x);

result:

vector([1/2*x^2, z*x, y*x, z*x])


ans =

[ 1/2*x^2,
y*x]

[
z*x,
z*x]


ccode
fortran
都是不错的代码生成工具哦
colspace
Basis for column space
列空间的基
eq符号测试 是否相等
expm
Symbolic matrix exponential
矩阵指数函数
这个比较常用的
ezplot
系列
用于出图非常容易
funtool
非常好用的一个工具
也是可以学习其
gui设计技术

help mfunlist

MFUNLIST Special functions for MFUN.


The following special functions are listed in alphabetical order


according to the third column. n denotes an integer argument,


x denotes a real argument, and z denotes a complex argument. For


more detailed descriptions of the functions, including any


argument restrictions, see the Reference Manual, or use MHELP.



bernoulli
n
Bernoulli Numbers


bernoulli
n,z
Bernoulli Polynomials


BesselI
x1,x
Bessel Function of the First Kind


BesselJ
x1,x
Bessel Function of the First Kind


BesselK
x1,x
Bessel Function of the Second Kind


BesselY
x1,x
Bessel Function of the Second Kind


Beta
z1,z2
Beta Function


binomial
x1,x2
Binomial Coefficients


EllipticF -
z,k
Incomplete Elliptic Integral, First Kind


EllipticK -
k
Complete Elliptic Integral, First Kind


EllipticCK -
k
Complementary Complete Integral, First Kind


EllipticE -
k
Complete Elliptic Integrals, Second Kind


EllipticE -
z,k
Incomplete Elliptic Integrals, Second Kind


EllipticCE -
k
Complementary Complete Elliptic Integral, Second Kind


EllipticPi -
nu,k
Complete Elliptic Integrals, Third Kind


EllipticPi -
z,nu,k
Incomplete Elliptic Integrals, Third Kind


EllipticCPi -
nu,k
Complementary Complete Elliptic Integral, Third Kind


erfc
z
Complementary Error Function


erfc
n,z
Complementary Error Function's Iterated Integrals


Ci
z
Cosine Integral


dawson
x
Dawson's Integral


Psi
z
Digamma Function


dilog
x
Dilogarithm Integral


erf
z
Error Function


euler
n
Euler Numbers


euler
n,z
Euler Polynomials


Ei
x
Exponential Integral


Ei
n,z
Exponential Integral


FresnelC
x
Fresnel Cosine Integral


FresnelS
x
Fresnel Sine Integral


GAMMA
z
Gamma Function


harmonic

n
Harmonic Function


Chi
z
Hyperbolic Cosine Integral


Shi
z
Hyperbolic Sine Integral


GAMMA
z1,z2
Incomplete Gamma Function


W
z
Lambert's W Function


W
n,z
Lambert's W Function


lnGAMMA
z
Logarithm of the Gamma function


Li
x
Logarithmic Integral


Psi
n,z
Polygamma Function


Ssi
z
Shifted Sine Integral


Si
z
Sine Integral


Zeta
z
(Riemann) Zeta Function


Zeta
n,z
(Riemann) Zeta Function


Zeta
n,z,x
(Riemann) Zeta Function



Orthogonal Polynomials (Extended Symbolic Math Toolbox only)


T
n,x
Chebyshev of the First Kind


U

n,x
Chebyshev of the Second Kind


G
n,x1,x
Gegenbauer


H
n,x
Hermite


P
n,x1,x2,x
Jacobi


L
n,x
Laguerre


L
n,x1,x
Generalized Laguerre


P
n,x
Legendre



See also mfun, mhelp.



Reference page in Help browser


doc mfunlist

numden
Numerator and denominator
用于获得分子分母
procread
Install Maple procedure
似乎是比较难的用法了
Suppose the file ident.src contains the following
source text for a Maple procedure.ident := proc(A)
#
ident(A) computes A*inverse(A)


local X;


X := inverse(A);


evalm(A &* X);

end;
Then the statement
procread('ident.src') installs the procedure. It can be accessed with
maple('ident',magic(3))ormaple('ident',vpa(magic(3)))
用于 自定义文件, 使用 注意 引号,文件名的 引号
梯形
echelon form
rref
是矩阵的简化 梯形 形式
sym(magic(4))
rref(ans)
ans =

[ 16,
2,
3, 13]

[
5, 11, 10,
8]

[
9,
7,
6, 12]

[
4, 14, 15,
1]



>> rref(ans)
statement:

gaussjord(matrix([[16,2,3,13],[5,11,10,8],[9,7,6,12],[4,14,15,1]]));

result:

matrix([[1, 0, 0, 1], [0, 1, 0, 3], [0, 0, 1, -3], [0, 0, 0, 0]])


ans =

[
1,
0,
0,
1]

[
0,
1,
0,
3]

[
0,
0,
1, -3]

[
0,
0,
0,
0]

实际上是高斯约旦矩阵
rsums
Interactive evaluation of Riemann sums


Syntax


rsums(f)rsums(f,a,b)rsums(f,[a,b])Description

黎曼和 实际上应该是求积分吧
而且是可以交互的,
就是可以改变积分的步长

开始讨论syms x ya =[ x, 1, 2; y*x , 3,4 ]
int(a,x,1,2)
int(ans,y,2,3)
double(ans)
这是对函数矩阵积分的命令, 两个 int 是双重的积分哦,
先对x积分,后对y,积分, 都是用符号积分的, 然后再 double,比较要注意的是这个积分仅仅限于 定上线积分的

如果变上限,把积分限 换成变量即可, int(a,x,sqrt(x),2)

matlab符号计算笔记.doc

130.5 KB, 下载次数: 40

评分

1

查看全部评分

回复
分享到:

使用道具 举报

发表于 2008-7-30 23:35 | 显示全部楼层
好,谢谢!:victory:
发表于 2008-7-30 23:40 | 显示全部楼层
内容不错,但是帖子的格式有点儿乱
发表于 2008-8-1 20:04 | 显示全部楼层

回复 楼主 的帖子

确实,完整的看了一遍,很多东西都写得很好,楼主有时间将其整理一下,可能更好哈
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-5-2 20:11 , Processed in 0.243649 second(s), 22 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表