Mupad 应用实践
2016-02-26 11:32
267 查看
Mupad学习记录1
Matlab自带的帮助文件是最好的教程,若想全部学习mupad用法,建议从头到尾看一下mupad帮助文档,打开办法:在Matlab命令栏输入 doc mupad 在弹出的窗口中找到mupad一栏
关于如何打开mupad
1)创建函数句柄
nb = allMuPADNotebooks
2)创建空白文档
nb = mupad或mupad
3) 打开欢迎界面
mupadwelcome
4) 在matlab主界面的“应用程序”中打开
Mupad的基本操作
1.执行命令 Enter
2.暂缓显示结果命令 :
3.换行命令 shift+enter 或 ctrl+enter
4.变量变更的作用范围修改 在mupad界面的notebook中点击关于evaluate的若干命令
5.自动填写 ctrl+space
6.命令窗口 View>Command Bar
7.命令窗口中的#symbols是等待修改的变量,用快捷键tab可以快速切换
8.关于帮助
1) info(#)
2) ?# 直接弹出相应的帮助文档,类似于matlab中的doc命令
3) 光标停留在相应位置
关于数值转化与复数
float(sqrt(56))
float(1.0/3*exp(1)*sin(2))
DIGITS:=20: float(sqrt(56))
DIGITS:=30: float(PI); float(E); delete DIGITS
rectform(1/(sqrt(2) + I))
conjugate(1/(2^(1/2) + I)) 复数转化命令
Re(1/(2^(1/2) + I))
Im(1/(2^(1/2) + I)) 复数的显示问题
abs(1/(2^(1/2) + I))
arg(1/(2^(1/2) + I)) 计算模和极角
关于微分
f := y^2 + 4*x + 6*x^2 + 4*x^3 + x^4: diff(f, y) 求(偏)导
diff(diff(diff(sin(x), x), x), x)
diff(sin(x), x, x, x)
diff(sin(x), x $ 3)
diff(x^2*y^2 + 4*x^2*y + 6*x*y^2, y, x) 高阶(偏)导
其它命令
D D(sin) 注意D(sin)(x^2) 结果显示cos(x^2) 改进方法是自定义函数f := x -> sin(x^2): D(f)
' sin'
关于积分
int((cos(x))^3, x) 不定积分
int((cos(x))^3, x = 0..PI/4) 定积分
int(sin(x)/x, x = -infinity..infinity) 广义积分
当结果不收敛时返回积分公式
numeric::int(sin(x^2)^2, x = -1..1)
float(int(sin(x^2)^2,(x = -1..1))) 常见数值转化公式
关于线性代数
A := matrix([[1, 2], [3, 4], [5, 6]])
B := matrix([[1, 2, 3], [4, 5, 6]])
C := matrix(3, 3, [[-1, -2, -3], [-4, -5, -6], [-7, -8, -9]]) 矩阵的创建
F := matrix(3, 3, [[1, -1, 0], [2, -2]]) 空余位置以0补齐,多余位置返回错误
G := matrix(4, 4, [1, 2, 3, 4], Diagonal) 建立对角矩阵
A*B 乘法运算
C + 10 加上10乘以单位矩阵
det(G) 行列式
1/G 逆矩阵
linalg::eigenvalues(F) 直接求出矩阵F的特征值
关于方程
solve(x^5 + 3*x^4 - 23*x^3 - 51*x^2 + 94*x + 120 = 0, x) 单变量方程
solve(a*x^2 + b*x + c = 0, x) 参数方程
solve([x^2 + x*y + y^2 = 1, x^2 - y^2 = 0], [x, y]) 解方程组
solve([x^2 + y^2 = a, x^2 - y^2 = b], [x, y]) 解含参方程组
o := ode(x^2*diff(y(x), x, x) + 2*x*diff(y(x), x) + x, y(x)):
solve(o) 解常微分方程
solve(x^4 >= 5, x) 解不等式
assume(x in R_); solve(x^4 >= 5, x)
solve(x^4 >= 5, x) assuming x > 0 一定假设下的解方程,否则结果分类讨论十分繁琐
solve(a*x^2 + b*x + c = 0, x) assuming a > 0
solve(x^(5/2) = 1, x) assuming x in R_
solve(x^4 - a = 0, x) assuming a = 16 and x in R_
关于多项式
factor(x^12 - 1) 因式分解
expand((x - 1)*(x + 1)*(x^2 + x + 1)*(x^2 + 1)*(x^2 - x + 1)*(x^4 - x^2 + 1)) 合并运算
collect((x - a)^4 + a*x^3 + b^2*x + b*x + 10*a^4 +(b + a*x)^2, x) 定义未定元的多项式整理
partfrac((7*x^2 + 7*x + 6)/(x^3 + 2*x^2 + 2*x + 1)) 分式的整理
simplify((x - 1)*(x + 1)*(x^2 + x + 1)*(x^2 + 1)*(x^2 - x + 1)*(x^4 - x^2 + 1))
Simplify((x - 1)*(x + 1)*(x^2 + x + 1)*(x^2 + 1)*(x^2 - x + 1)*(x^4 - x^2 + 1)) 简化命令
expand(sin(5*x)) 三角函数的分解
simplify(sqrt(x^2 + 2*x + 1) + sqrt(x^2 - 2*x + 1) + sqrt(x^2 + 4*x + 4) + sqrt(x^2 - 4*x + 4)) assuming x > 2 假设条件下的化简
注意
进行完一步计算之后我们需要删除命令
delete f:
Mupad学习记录2
这一节着重学习关于绘图及其动画控制
绘图
1)一般绘图
plot(sin(x)*cos(3*x)) 绘制二维图
plot(sin(x)*sin(y), #3D) 绘制三维图(#3D替代二维动画)
plot(sin(x), cos(x), tan(x), cot(x) 多个图形在同一张纸里
plot(sin(k*x) $ k = 1..3) 使用$符号使得一系列图画在一张纸上(二维)
plot(-sqrt(r^2 - x^2 - y^2) $ r = 1..5, #3D) 使用$符号使得一系列图画在一张纸上(三维)
plot(sin(x^3)*exp(x), x = 3..5) 使用x=#..#确定作图范围(二维)
plot(sin(x)*sin(y), x = 0..3, y = 1..3, #3D) 使用x=#..#,y=#..#确定作图范围(三维)
plot(sin(k*x) $ k = 1..5, x = 0..2*PI) 在关于$的系列图中设定范围
plot({sin(k*x), k*t^2} $ k = 1..5, x = 0..2*PI, t = -1..1) 多幅系列图的画法及其范围
plot(piecewise([x < - 2, - 1], [-1 < x and x < 0, x^2], [0 < x and x < 1, -x^2], [x > 1, 1])) 分段函数的画法
通过界面直接修改图形属性,而非使用编码修改,如果点击目标对象无反应,选择菜单View > Object Browser
在图形界面,可以自由旋转,缩放,以及自动旋转等,相关命令在图形窗口界面,自行尝试,概不赘述
动画
1)关于参数的动画
plot(exp(x)*sin(a^2*x), x = 1..2, a = 2..6) 二维直角坐标动画
plot(sin(a*x^2 + a*y^2), x = -2..2, y = -2..2, a = 0.1..2, #3D) 三维直角坐标动画
例子1
plot(
plot::Function2d(a*sin(x), x = 0..a*PI, a = 0.5..1),
plot::Rectangle(0..a*PI, 0..a, a = 0.5..1,
LineColor = RGB::Black),
plot::Line2d([0, 0], [PI*a, a], a = 0.5 ..1,
LineColor = RGB::Black)
//其中的plot::Rectangle和plot::Line2d分别是矩形作图和直线作图
例子2
plot(plot::Arc2d(1 + a, [0, 0], AngleRange = 0..a*PI, a = 0..1)):
//其中的plot::Arc2d是指plot::Arc2d(半径,中心,弧线角度范围,动画参数a)
例子3
plot(plot::Function2d(4*a*x, x = 0..1, a = 0..1),
plot::Function2d(b*x^2, x = 0..1, b = 1..4)):
//这是将两幅参数动画画到同一幅图片中,参数的名称不同,注意参数名称是全局变量,必须不同
例子4
f := (x, y) -> 4 - (x - a)^2 - (y - a)^2:
mycolor := proc(x, y, z, a)
local t;
begin
t := sqrt((x - a)^2 + (y - a)^2):
if t < 0.1 then
return(RGB::Red)
elif t < 0.4 then
return(RGB::Orange)
elif t < 0.7 then
return(RGB::Green)
else return(RGB::Blue)
end_if;
end:
plot(plot::Function3d(f, x = -1..1, y = -1..1, a = -1..1,
FillColorFunction = mycolor)):
//这个例子展示了如何用全局变量t定义调色函数myclolor,其中proc是定义程序的命令(procedure的缩写),local等也是相应配套命令,详情可以用?local命令查看帮助文档
例子5
plot(plot::Point2d([a, sin(a)], a = 0..2*PI,
Frames = 100, TimeRange = 0..5)):
//5秒100帧
plot(plot::Point2d([a, sin(a)], a = 0..2*PI,
Frames = 200, TimeRange = 0..5)):
//5秒200帧,增加帧可以使动画更光滑,默认是50帧,根据人眼特性,n<25(t1-t0)是合适的帧数
例子6
p1 := plot::Point2d(-1, sin(a), a = 0..PI, Color = RGB::Red,
PointSize = 5*unit::mm,
TimeBegin = 0, TimeEnd = 5):
p2 := plot::Point2d(0, sin(a), a = 0..PI, Color = RGB::Green,
PointSize = 5*unit::mm,
TimeBegin = 6, TimeEnd = 12):
p3 := plot::Point2d(1, sin(a), a = 0..PI, Color = RGB::Blue,
PointSize = 5*unit::mm,
TimeBegin = 9, TimeEnd = 15):
plot(p1, p2, p3, PointSize = 3.0*unit::mm,
YAxisVisible = FALSE):
//多个对象的动画设定,动画的先后顺序通过timebegin和timeend来控制
例子7
p2::VisibleAfterEnd := FALSE:
p3::VisibleBeforeBegin := FALSE:
plot(p1, p2, p3, PointSize = 3.0*unit::mm,
YAxisVisible = FALSE):
//通过Visible命令控制动画前后的可见性
//常见命令有VisibleAfter = t0,VisibleBefore = t1,VisibleFromTo = t0..t1等,详见帮助文档
例子8
p1 := plot::Point2d(-1, sin(a), a = 0..PI, Color = RGB::Red,
PointSize = 5*unit::mm,
TimeBegin = 0, TimeEnd = 5):
p2 := plot::Point2d(0, sin(a), a = 0..PI, Color = RGB::Green,
PointSize = 5*unit::mm,
TimeBegin = 6, TimeEnd = 12):
p3 := plot::Point2d(1, sin(a), a = 0..PI, Color = RGB::Blue,
PointSize = 5*unit::mm,
TimeBegin = 9, TimeEnd = 15):
p2::VisibleAfterEnd := FALSE:
p3::VisibleBeforeBegin := FALSE:
p4 := plot::Point2d(0.5, 0.5, Color = RGB::Black,
PointSize = 5*unit::mm,
VisibleFromTo = 7..13):
plot(p1, p2, p3, p4, PointSize = 3.0*unit::mm,
YAxisVisible = FALSE):
//多个对象,静止和运动交互出现的控制
例子9
for i from 0 to 101 do
t[i] := i/10;
end_for:
for i from 0 to 100 do
x := i/100*PI;
myframe[i] := plot::Group2d(
plot::Point2d([x, sin(x)], Color = RGB::Red),
plot::Point2d([x, cos(x)], Color = RGB::Blue),
VisibleFromTo = t[i]..t[i + 1]);
end_for:
plot(myframe[i] $ i = 0..100, PointSize = 5.0*unit::mm):
//这是所谓的"Frame by frame animations",通过编程实现动画
例子10
delete i:
plot(plot::Point2d([i/100*PI, sin(i/100*PI)], i = 0..100,
Color = RGB::Red),
plot::Point2d([i/100*PI, cos(i/100*PI)], i = 0..100,
Color = RGB::Blue),
Frames = 101, TimeRange = 0..10,
PointSize = 5.0*unit::mm):
//例9同样可以用一般动画命令来实现
例子11
f := x -> -sqrt(1 - x^2):
plot(// The static rim:
plot::Function2d(f(x), x = -1..1, Color = RGB::Black),
// The incoming rays:
plot::Line2d([x, 2], [x, f(x)], VisibleAfter = 5*x
) $ x in [-1 + i/20 $ i = 1..39],
// The reflected rays leaving to the right:
plot::Line2d([x, f(x)],
[1, f(x) + (1-x)*(f'(x) - 1/f'(x))/2],
Color = RGB::Orange, VisibleAfter = 5*x
) $ x in [-1 + i/20 $ i = 1..19],
// The reflected rays leaving to the left:
plot::Line2d([x, f(x)],
[-1, f(x) - (x+1)*(f'(x) - 1/f'(x))/2],
Color = RGB::Orange, VisibleAfter = 5*x
) $ x in [-1 + i/20 $ i = 21..39],
ViewingBox = [-1..1, -1..1]):
//运用visibleafter命令,将已经画好的图像逐步呈现,以达到动画效果,这是一种常见的简单动画制作方法
应用实例展示
例子12
DIGITS := 2:
// the function:
f := x -> cos(x^2):
// the anti-derivative:
F := x -> numeric::int(f(y), y = 0..x):
// the graph of f(x):
g := plot::Function2d(f(x), x = 0..6, Color = RGB::Blue):
// the graph of F(x):
G := plot::Function2d(F(x), x = 0..6, Color = RGB::Black):
// a point moving along the graph of F(x):
p := plot::Point2d([a, F(a)], a = 0..6, Color = RGB::Black):
// hatched region between the origin and the moving point p:
h := plot::Hatch(g, 0, 0 ..a, a = 0..6, Color = RGB::Red):
// the right border line of the hatched region:
l := plot::Line2d([a, 0], [a, f(a)], a = 0..6,
Color = RGB::Red):
// a dashed vertical line from f to F:
L1 := plot::Line2d([a, f(a)], [a, F(a)], a = 0..6,
Color = RGB::Black, LineStyle = Dashed):
// a dashed horizontal line from the y axis to F:
L2 := plot::Line2d([-0.1, F(a)], [a, F(a)], a = 0..6,
Color = RGB::Black, LineStyle = Dashed):
// the current value of F at the moving point p:
t := plot::Text2d(a -> F(a), [-0.2, F(a)], a = 0..6,
HorizontalAlignment = Right):
plot(g, G, p, h, l, L1, L2, t,
YTicksNumber = None, YTicksAt = [-1, 1]):
delete DIGITS:
//积分动画
例子13
c := a -> 1/2 *(1 - 1/sin(PI/2*a)):
mycolor := (u, v, x, y, z) -> [(u - 0.8)/0.4, 0, (1.2 - u)/0.4]:
rectangle2annulus := plot::Surface(
[c(a) + (u - c(a))*cos(PI*v), (u - c(a))*sin(PI*v), 0],
u = 0.8..1.2, v = -a..a, a = 1/10^10..1,
FillColorFunction = mycolor, Mesh = [3, 40], Frames = 40):
plot(rectangle2annulus, Axes = None,
CameraDirection = [-11, -3, 3]):
//圆盘动画
annulus2moebius := plot::Surface(
[((u - 1)*cos(a*v*PI/2) + 1)*cos(PI*v),
((u - 1)*cos(a*v*PI/2) + 1)*sin(PI*v),
(u - 1)*sin(a*v*PI/2)],
u = 0.8..1.2, v = -1..1, a = 0..1,
FillColorFunction = mycolor, Mesh = [3, 40], Frames = 20):
plot(annulus2moebius, Axes = None,
CameraDirection = [-11, -3, 3]):
//折叠动画
rectangle2annulus::VisibleFromTo := 0..5:
annulus2moebius::VisibleFromTo := 5..7:
plot(rectangle2annulus, annulus2moebius, Axes = None,
CameraDirection = [-11, -3, 3]):
//连接前两个动画
//莫比乌斯带
例子14
ms := 1: m1 := 0.04: m2 := 0.0001:
//设定三体质量
Y := numeric::odesolve2(numeric::ode2vectorfield(
{xs''(t) =
-m1*(xs(t)-x1(t))/sqrt((xs(t)-x1(t))^2 + (ys(t)-y1(t))^2)^3
-m2*(xs(t)-x2(t))/sqrt((xs(t)-x2(t))^2 + (ys(t)-y2(t))^2)^3,
ys''(t) =
-m1*(ys(t)-y1(t))/sqrt((xs(t)-x1(t))^2 + (ys(t)-y1(t))^2)^3
-m2*(ys(t)-y2(t))/sqrt((xs(t)-x2(t))^2 + (ys(t)-y2(t))^2)^3,
x1''(t) =
-ms*(x1(t)-xs(t))/sqrt((x1(t)-xs(t))^2 + (y1(t)-ys(t))^2)^3
-m2*(x1(t)-x2(t))/sqrt((x1(t)-x2(t))^2 + (y1(t)-y2(t))^2)^3,
y1''(t) =
-ms*(y1(t)-ys(t))/sqrt((x1(t)-xs(t))^2 + (y1(t)-ys(t))^2)^3
-m2*(y1(t)-y2(t))/sqrt((x1(t)-x2(t))^2 + (y1(t)-y2(t))^2)^3,
x2''(t) =
-ms*(x2(t)-xs(t))/sqrt((x2(t)-xs(t))^2 + (y2(t)-ys(t))^2)^3
-m1*(x2(t)-x1(t))/sqrt((x2(t)-x1(t))^2 + (y2(t)-y1(t))^2)^3,
y2''(t) =
-ms*(y2(t)-ys(t))/sqrt((x2(t)-xs(t))^2 + (y2(t)-ys(t))^2)^3
-m1*(y2(t)-y1(t))/sqrt((x2(t)-x1(t))^2 + (y2(t)-y1(t))^2)^3,
xs(0) = -m1 , x1(0) = ms, x2(0) = 0,
ys(0) = 0.7*m2, y1(0) = 0, y2(0) = -0.7*ms,
xs'(0) = -1.01*m2, x1'(0) = 0, x2'(0) = 1.01*ms,
ys'(0) = -0.9*m1, y1'(0) = 0.9*ms, y2'(0) = 0},
[xs(t), xs'(t), ys(t), ys'(t),
x1(t), x1'(t), y1(t), y1'(t),
x2(t), x2'(t), y2(t), y2'(t)]
)):
//解ODE方程并输入相关公式
dt := 0.05: imax := 516:
plot(// The sun:
plot::Point2d(Y(t)[1], Y(t)[3], Color = RGB::Orange,
VisibleFromTo = t..t + 0.99*dt,
PointSize = 4*unit::mm
) $ t in [i*dt $ i = 0..imax],
// The giant planet:
plot::Point2d(Y(t)[5], Y(t)[7], Color = RGB::Red,
VisibleFromTo = t..t + 0.99*dt,
PointSize = 3*unit::mm
) $ t in [i*dt $ i = 0..imax],
// The orbit of the giant planet:
plot::Line2d([Y(t - dt)[5], Y(t - dt)[7]],
[Y(t)[5], Y(t)[7]], Color = RGB::Red,
VisibleAfter = t
) $ t in [i*dt $ i = 1..imax],
// The small planet:
plot::Point2d(Y(t)[9], Y(t)[11], Color = RGB::Blue,
VisibleFromTo = t..t + 0.99*dt,
PointSize = 2*unit::mm
) $ t in [i*dt $ i = 0..imax],
// The orbit of the small planet:
plot::Line2d([Y(t - dt)[9], Y(t - dt)[11]],
[Y(t)[9], Y(t)[11]], Color = RGB::Blue,
VisibleAfter = t
) $ t in [i*dt $ i = 1..imax]
):
//运用"frame by frame"制定三体运动动画
Mupad学习记录3
这节我基于Mupad,对螺旋线作图及其动画做一个探究
及其过程中学习到的控制命令
在这一过程中,学习到了以下几个功能及其命令:
镜头 plot::Camera
排版 Layout = #
标题 Footer, Header
字体 HeaderFont
字体位置 HeaderAlignment
变光滑 AdaptiveMesh
划分 UMesh
多图合并 plot::Scene3d
坐标数据 TicksNumber = None (plot settings)
坐标标示 TicksAt
颜色调整 FillColorFunction, Color=#
原比例尺 Scaling=Constrained
点列 plot::PointList3d
扫面 plot::Sweep
组图 plot::Group3d
点法式平面 plot::Plane
三点式平面 plot::Polygon3d
空间圆 plot::Circle3d
切平面 plot::Parallelogram3d
摆线 WheelRadius
坐标变换 Transformations
这些都是在帮助文档中可以找到详细用法,需要相关命令时查阅帮助文档就可以了
Mupad学习记录4
动画遇到的问题及其解决办法
以下是我在实践中遇到的种种问题,经过反复调试才得到解决,我把这些经验写在这里
1,布局问题
用Layout命令对全是动画或全是静图的Scened2d/3d是奏效的,但是当两者一起,plot命令总是把静图优先放置,导致Horizontal命令失效,这时需要用Layout = Relative命令,自行编制动画位置,方可解决
Mupad学习记录5(关于符号)
Mupad notebook提供了良好的编辑界面,对于想基于该界面,制作报告课件等的用户,了解如何编辑符号公式等就显得很必要。
这一节的帮助文档,详见“Symbols and Special Characters”
Symbol::accentAsterisk 带星号
Symbol::accentTilde 带上弯线
Symbol::accentHat 带上角标
Symbol::accentRightArrow 带向量箭头
Symbol::accentDot 带点
Symbol::accentDoubleDot 带双点
Symbol::accentTripleDot 带三点
Symbol::accentOverBar 带上划线
Symbol::accentUnderBar 带下划线
Symbol::new 调取通用字符(参见Typeset Symbols)
Symbol::subScript 下标
Symbol::subSuperScript 上下标
Symbol::superScript 上标
output::mathText 输出含数学公式的语句
output::ordinal 输出数字序数
output::roman 输出罗马序数
output::tableForm 输出表列
output::tree 输出树状图
修改结果,不缩写化简 Pref::abbreviateOutput(FALSE):
关闭优化字符显示 PRETTYPRINT := FALSE
常见错误分析:
Error: The argument is invalid. [xmlprint::beginElement]
Evaluating: plot
定义的自变量有问题,且只要出现 invalid 一般都说明是拼写出现错误,特别是大小写
Error: The argument 'Umesh = 10' is unexpected. [plot::Curve3d::new]
一般是拼写有误
Error: Unexpected 'identifier'. [line 6, col 1]
缺少冒号
The attribute 'VMesh' in the 'Surface' object must be a positive integer number. [plot]
循环语句i的初始值或末值超出范围,或初值为0,或末值有误
画图结果多出对象,检查最后的plot(中是否多打字母)
Matlab自带的帮助文件是最好的教程,若想全部学习mupad用法,建议从头到尾看一下mupad帮助文档,打开办法:在Matlab命令栏输入 doc mupad 在弹出的窗口中找到mupad一栏
关于如何打开mupad
1)创建函数句柄
nb = allMuPADNotebooks
2)创建空白文档
nb = mupad或mupad
3) 打开欢迎界面
mupadwelcome
4) 在matlab主界面的“应用程序”中打开
Mupad的基本操作
1.执行命令 Enter
2.暂缓显示结果命令 :
3.换行命令 shift+enter 或 ctrl+enter
4.变量变更的作用范围修改 在mupad界面的notebook中点击关于evaluate的若干命令
5.自动填写 ctrl+space
6.命令窗口 View>Command Bar
7.命令窗口中的#symbols是等待修改的变量,用快捷键tab可以快速切换
8.关于帮助
1) info(#)
2) ?# 直接弹出相应的帮助文档,类似于matlab中的doc命令
3) 光标停留在相应位置
关于数值转化与复数
float(sqrt(56))
float(1.0/3*exp(1)*sin(2))
DIGITS:=20: float(sqrt(56))
DIGITS:=30: float(PI); float(E); delete DIGITS
rectform(1/(sqrt(2) + I))
conjugate(1/(2^(1/2) + I)) 复数转化命令
Re(1/(2^(1/2) + I))
Im(1/(2^(1/2) + I)) 复数的显示问题
abs(1/(2^(1/2) + I))
arg(1/(2^(1/2) + I)) 计算模和极角
关于微分
f := y^2 + 4*x + 6*x^2 + 4*x^3 + x^4: diff(f, y) 求(偏)导
diff(diff(diff(sin(x), x), x), x)
diff(sin(x), x, x, x)
diff(sin(x), x $ 3)
diff(x^2*y^2 + 4*x^2*y + 6*x*y^2, y, x) 高阶(偏)导
其它命令
D D(sin) 注意D(sin)(x^2) 结果显示cos(x^2) 改进方法是自定义函数f := x -> sin(x^2): D(f)
' sin'
关于积分
int((cos(x))^3, x) 不定积分
int((cos(x))^3, x = 0..PI/4) 定积分
int(sin(x)/x, x = -infinity..infinity) 广义积分
当结果不收敛时返回积分公式
numeric::int(sin(x^2)^2, x = -1..1)
float(int(sin(x^2)^2,(x = -1..1))) 常见数值转化公式
关于线性代数
A := matrix([[1, 2], [3, 4], [5, 6]])
B := matrix([[1, 2, 3], [4, 5, 6]])
C := matrix(3, 3, [[-1, -2, -3], [-4, -5, -6], [-7, -8, -9]]) 矩阵的创建
F := matrix(3, 3, [[1, -1, 0], [2, -2]]) 空余位置以0补齐,多余位置返回错误
G := matrix(4, 4, [1, 2, 3, 4], Diagonal) 建立对角矩阵
A*B 乘法运算
C + 10 加上10乘以单位矩阵
det(G) 行列式
1/G 逆矩阵
linalg::eigenvalues(F) 直接求出矩阵F的特征值
关于方程
solve(x^5 + 3*x^4 - 23*x^3 - 51*x^2 + 94*x + 120 = 0, x) 单变量方程
solve(a*x^2 + b*x + c = 0, x) 参数方程
solve([x^2 + x*y + y^2 = 1, x^2 - y^2 = 0], [x, y]) 解方程组
solve([x^2 + y^2 = a, x^2 - y^2 = b], [x, y]) 解含参方程组
o := ode(x^2*diff(y(x), x, x) + 2*x*diff(y(x), x) + x, y(x)):
solve(o) 解常微分方程
solve(x^4 >= 5, x) 解不等式
assume(x in R_); solve(x^4 >= 5, x)
solve(x^4 >= 5, x) assuming x > 0 一定假设下的解方程,否则结果分类讨论十分繁琐
solve(a*x^2 + b*x + c = 0, x) assuming a > 0
solve(x^(5/2) = 1, x) assuming x in R_
solve(x^4 - a = 0, x) assuming a = 16 and x in R_
关于多项式
factor(x^12 - 1) 因式分解
expand((x - 1)*(x + 1)*(x^2 + x + 1)*(x^2 + 1)*(x^2 - x + 1)*(x^4 - x^2 + 1)) 合并运算
collect((x - a)^4 + a*x^3 + b^2*x + b*x + 10*a^4 +(b + a*x)^2, x) 定义未定元的多项式整理
partfrac((7*x^2 + 7*x + 6)/(x^3 + 2*x^2 + 2*x + 1)) 分式的整理
simplify((x - 1)*(x + 1)*(x^2 + x + 1)*(x^2 + 1)*(x^2 - x + 1)*(x^4 - x^2 + 1))
Simplify((x - 1)*(x + 1)*(x^2 + x + 1)*(x^2 + 1)*(x^2 - x + 1)*(x^4 - x^2 + 1)) 简化命令
expand(sin(5*x)) 三角函数的分解
simplify(sqrt(x^2 + 2*x + 1) + sqrt(x^2 - 2*x + 1) + sqrt(x^2 + 4*x + 4) + sqrt(x^2 - 4*x + 4)) assuming x > 2 假设条件下的化简
注意
进行完一步计算之后我们需要删除命令
delete f:
Mupad学习记录2
这一节着重学习关于绘图及其动画控制
绘图
1)一般绘图
plot(sin(x)*cos(3*x)) 绘制二维图
plot(sin(x)*sin(y), #3D) 绘制三维图(#3D替代二维动画)
plot(sin(x), cos(x), tan(x), cot(x) 多个图形在同一张纸里
plot(sin(k*x) $ k = 1..3) 使用$符号使得一系列图画在一张纸上(二维)
plot(-sqrt(r^2 - x^2 - y^2) $ r = 1..5, #3D) 使用$符号使得一系列图画在一张纸上(三维)
plot(sin(x^3)*exp(x), x = 3..5) 使用x=#..#确定作图范围(二维)
plot(sin(x)*sin(y), x = 0..3, y = 1..3, #3D) 使用x=#..#,y=#..#确定作图范围(三维)
plot(sin(k*x) $ k = 1..5, x = 0..2*PI) 在关于$的系列图中设定范围
plot({sin(k*x), k*t^2} $ k = 1..5, x = 0..2*PI, t = -1..1) 多幅系列图的画法及其范围
plot(piecewise([x < - 2, - 1], [-1 < x and x < 0, x^2], [0 < x and x < 1, -x^2], [x > 1, 1])) 分段函数的画法
通过界面直接修改图形属性,而非使用编码修改,如果点击目标对象无反应,选择菜单View > Object Browser
在图形界面,可以自由旋转,缩放,以及自动旋转等,相关命令在图形窗口界面,自行尝试,概不赘述
动画
1)关于参数的动画
plot(exp(x)*sin(a^2*x), x = 1..2, a = 2..6) 二维直角坐标动画
plot(sin(a*x^2 + a*y^2), x = -2..2, y = -2..2, a = 0.1..2, #3D) 三维直角坐标动画
例子1
plot(
plot::Function2d(a*sin(x), x = 0..a*PI, a = 0.5..1),
plot::Rectangle(0..a*PI, 0..a, a = 0.5..1,
LineColor = RGB::Black),
plot::Line2d([0, 0], [PI*a, a], a = 0.5 ..1,
LineColor = RGB::Black)
//其中的plot::Rectangle和plot::Line2d分别是矩形作图和直线作图
例子2
plot(plot::Arc2d(1 + a, [0, 0], AngleRange = 0..a*PI, a = 0..1)):
//其中的plot::Arc2d是指plot::Arc2d(半径,中心,弧线角度范围,动画参数a)
例子3
plot(plot::Function2d(4*a*x, x = 0..1, a = 0..1),
plot::Function2d(b*x^2, x = 0..1, b = 1..4)):
//这是将两幅参数动画画到同一幅图片中,参数的名称不同,注意参数名称是全局变量,必须不同
例子4
f := (x, y) -> 4 - (x - a)^2 - (y - a)^2:
mycolor := proc(x, y, z, a)
local t;
begin
t := sqrt((x - a)^2 + (y - a)^2):
if t < 0.1 then
return(RGB::Red)
elif t < 0.4 then
return(RGB::Orange)
elif t < 0.7 then
return(RGB::Green)
else return(RGB::Blue)
end_if;
end:
plot(plot::Function3d(f, x = -1..1, y = -1..1, a = -1..1,
FillColorFunction = mycolor)):
//这个例子展示了如何用全局变量t定义调色函数myclolor,其中proc是定义程序的命令(procedure的缩写),local等也是相应配套命令,详情可以用?local命令查看帮助文档
例子5
plot(plot::Point2d([a, sin(a)], a = 0..2*PI,
Frames = 100, TimeRange = 0..5)):
//5秒100帧
plot(plot::Point2d([a, sin(a)], a = 0..2*PI,
Frames = 200, TimeRange = 0..5)):
//5秒200帧,增加帧可以使动画更光滑,默认是50帧,根据人眼特性,n<25(t1-t0)是合适的帧数
例子6
p1 := plot::Point2d(-1, sin(a), a = 0..PI, Color = RGB::Red,
PointSize = 5*unit::mm,
TimeBegin = 0, TimeEnd = 5):
p2 := plot::Point2d(0, sin(a), a = 0..PI, Color = RGB::Green,
PointSize = 5*unit::mm,
TimeBegin = 6, TimeEnd = 12):
p3 := plot::Point2d(1, sin(a), a = 0..PI, Color = RGB::Blue,
PointSize = 5*unit::mm,
TimeBegin = 9, TimeEnd = 15):
plot(p1, p2, p3, PointSize = 3.0*unit::mm,
YAxisVisible = FALSE):
//多个对象的动画设定,动画的先后顺序通过timebegin和timeend来控制
例子7
p2::VisibleAfterEnd := FALSE:
p3::VisibleBeforeBegin := FALSE:
plot(p1, p2, p3, PointSize = 3.0*unit::mm,
YAxisVisible = FALSE):
//通过Visible命令控制动画前后的可见性
//常见命令有VisibleAfter = t0,VisibleBefore = t1,VisibleFromTo = t0..t1等,详见帮助文档
例子8
p1 := plot::Point2d(-1, sin(a), a = 0..PI, Color = RGB::Red,
PointSize = 5*unit::mm,
TimeBegin = 0, TimeEnd = 5):
p2 := plot::Point2d(0, sin(a), a = 0..PI, Color = RGB::Green,
PointSize = 5*unit::mm,
TimeBegin = 6, TimeEnd = 12):
p3 := plot::Point2d(1, sin(a), a = 0..PI, Color = RGB::Blue,
PointSize = 5*unit::mm,
TimeBegin = 9, TimeEnd = 15):
p2::VisibleAfterEnd := FALSE:
p3::VisibleBeforeBegin := FALSE:
p4 := plot::Point2d(0.5, 0.5, Color = RGB::Black,
PointSize = 5*unit::mm,
VisibleFromTo = 7..13):
plot(p1, p2, p3, p4, PointSize = 3.0*unit::mm,
YAxisVisible = FALSE):
//多个对象,静止和运动交互出现的控制
例子9
for i from 0 to 101 do
t[i] := i/10;
end_for:
for i from 0 to 100 do
x := i/100*PI;
myframe[i] := plot::Group2d(
plot::Point2d([x, sin(x)], Color = RGB::Red),
plot::Point2d([x, cos(x)], Color = RGB::Blue),
VisibleFromTo = t[i]..t[i + 1]);
end_for:
plot(myframe[i] $ i = 0..100, PointSize = 5.0*unit::mm):
//这是所谓的"Frame by frame animations",通过编程实现动画
例子10
delete i:
plot(plot::Point2d([i/100*PI, sin(i/100*PI)], i = 0..100,
Color = RGB::Red),
plot::Point2d([i/100*PI, cos(i/100*PI)], i = 0..100,
Color = RGB::Blue),
Frames = 101, TimeRange = 0..10,
PointSize = 5.0*unit::mm):
//例9同样可以用一般动画命令来实现
例子11
f := x -> -sqrt(1 - x^2):
plot(// The static rim:
plot::Function2d(f(x), x = -1..1, Color = RGB::Black),
// The incoming rays:
plot::Line2d([x, 2], [x, f(x)], VisibleAfter = 5*x
) $ x in [-1 + i/20 $ i = 1..39],
// The reflected rays leaving to the right:
plot::Line2d([x, f(x)],
[1, f(x) + (1-x)*(f'(x) - 1/f'(x))/2],
Color = RGB::Orange, VisibleAfter = 5*x
) $ x in [-1 + i/20 $ i = 1..19],
// The reflected rays leaving to the left:
plot::Line2d([x, f(x)],
[-1, f(x) - (x+1)*(f'(x) - 1/f'(x))/2],
Color = RGB::Orange, VisibleAfter = 5*x
) $ x in [-1 + i/20 $ i = 21..39],
ViewingBox = [-1..1, -1..1]):
//运用visibleafter命令,将已经画好的图像逐步呈现,以达到动画效果,这是一种常见的简单动画制作方法
应用实例展示
例子12
DIGITS := 2:
// the function:
f := x -> cos(x^2):
// the anti-derivative:
F := x -> numeric::int(f(y), y = 0..x):
// the graph of f(x):
g := plot::Function2d(f(x), x = 0..6, Color = RGB::Blue):
// the graph of F(x):
G := plot::Function2d(F(x), x = 0..6, Color = RGB::Black):
// a point moving along the graph of F(x):
p := plot::Point2d([a, F(a)], a = 0..6, Color = RGB::Black):
// hatched region between the origin and the moving point p:
h := plot::Hatch(g, 0, 0 ..a, a = 0..6, Color = RGB::Red):
// the right border line of the hatched region:
l := plot::Line2d([a, 0], [a, f(a)], a = 0..6,
Color = RGB::Red):
// a dashed vertical line from f to F:
L1 := plot::Line2d([a, f(a)], [a, F(a)], a = 0..6,
Color = RGB::Black, LineStyle = Dashed):
// a dashed horizontal line from the y axis to F:
L2 := plot::Line2d([-0.1, F(a)], [a, F(a)], a = 0..6,
Color = RGB::Black, LineStyle = Dashed):
// the current value of F at the moving point p:
t := plot::Text2d(a -> F(a), [-0.2, F(a)], a = 0..6,
HorizontalAlignment = Right):
plot(g, G, p, h, l, L1, L2, t,
YTicksNumber = None, YTicksAt = [-1, 1]):
delete DIGITS:
//积分动画
例子13
c := a -> 1/2 *(1 - 1/sin(PI/2*a)):
mycolor := (u, v, x, y, z) -> [(u - 0.8)/0.4, 0, (1.2 - u)/0.4]:
rectangle2annulus := plot::Surface(
[c(a) + (u - c(a))*cos(PI*v), (u - c(a))*sin(PI*v), 0],
u = 0.8..1.2, v = -a..a, a = 1/10^10..1,
FillColorFunction = mycolor, Mesh = [3, 40], Frames = 40):
plot(rectangle2annulus, Axes = None,
CameraDirection = [-11, -3, 3]):
//圆盘动画
annulus2moebius := plot::Surface(
[((u - 1)*cos(a*v*PI/2) + 1)*cos(PI*v),
((u - 1)*cos(a*v*PI/2) + 1)*sin(PI*v),
(u - 1)*sin(a*v*PI/2)],
u = 0.8..1.2, v = -1..1, a = 0..1,
FillColorFunction = mycolor, Mesh = [3, 40], Frames = 20):
plot(annulus2moebius, Axes = None,
CameraDirection = [-11, -3, 3]):
//折叠动画
rectangle2annulus::VisibleFromTo := 0..5:
annulus2moebius::VisibleFromTo := 5..7:
plot(rectangle2annulus, annulus2moebius, Axes = None,
CameraDirection = [-11, -3, 3]):
//连接前两个动画
//莫比乌斯带
例子14
ms := 1: m1 := 0.04: m2 := 0.0001:
//设定三体质量
Y := numeric::odesolve2(numeric::ode2vectorfield(
{xs''(t) =
-m1*(xs(t)-x1(t))/sqrt((xs(t)-x1(t))^2 + (ys(t)-y1(t))^2)^3
-m2*(xs(t)-x2(t))/sqrt((xs(t)-x2(t))^2 + (ys(t)-y2(t))^2)^3,
ys''(t) =
-m1*(ys(t)-y1(t))/sqrt((xs(t)-x1(t))^2 + (ys(t)-y1(t))^2)^3
-m2*(ys(t)-y2(t))/sqrt((xs(t)-x2(t))^2 + (ys(t)-y2(t))^2)^3,
x1''(t) =
-ms*(x1(t)-xs(t))/sqrt((x1(t)-xs(t))^2 + (y1(t)-ys(t))^2)^3
-m2*(x1(t)-x2(t))/sqrt((x1(t)-x2(t))^2 + (y1(t)-y2(t))^2)^3,
y1''(t) =
-ms*(y1(t)-ys(t))/sqrt((x1(t)-xs(t))^2 + (y1(t)-ys(t))^2)^3
-m2*(y1(t)-y2(t))/sqrt((x1(t)-x2(t))^2 + (y1(t)-y2(t))^2)^3,
x2''(t) =
-ms*(x2(t)-xs(t))/sqrt((x2(t)-xs(t))^2 + (y2(t)-ys(t))^2)^3
-m1*(x2(t)-x1(t))/sqrt((x2(t)-x1(t))^2 + (y2(t)-y1(t))^2)^3,
y2''(t) =
-ms*(y2(t)-ys(t))/sqrt((x2(t)-xs(t))^2 + (y2(t)-ys(t))^2)^3
-m1*(y2(t)-y1(t))/sqrt((x2(t)-x1(t))^2 + (y2(t)-y1(t))^2)^3,
xs(0) = -m1 , x1(0) = ms, x2(0) = 0,
ys(0) = 0.7*m2, y1(0) = 0, y2(0) = -0.7*ms,
xs'(0) = -1.01*m2, x1'(0) = 0, x2'(0) = 1.01*ms,
ys'(0) = -0.9*m1, y1'(0) = 0.9*ms, y2'(0) = 0},
[xs(t), xs'(t), ys(t), ys'(t),
x1(t), x1'(t), y1(t), y1'(t),
x2(t), x2'(t), y2(t), y2'(t)]
)):
//解ODE方程并输入相关公式
dt := 0.05: imax := 516:
plot(// The sun:
plot::Point2d(Y(t)[1], Y(t)[3], Color = RGB::Orange,
VisibleFromTo = t..t + 0.99*dt,
PointSize = 4*unit::mm
) $ t in [i*dt $ i = 0..imax],
// The giant planet:
plot::Point2d(Y(t)[5], Y(t)[7], Color = RGB::Red,
VisibleFromTo = t..t + 0.99*dt,
PointSize = 3*unit::mm
) $ t in [i*dt $ i = 0..imax],
// The orbit of the giant planet:
plot::Line2d([Y(t - dt)[5], Y(t - dt)[7]],
[Y(t)[5], Y(t)[7]], Color = RGB::Red,
VisibleAfter = t
) $ t in [i*dt $ i = 1..imax],
// The small planet:
plot::Point2d(Y(t)[9], Y(t)[11], Color = RGB::Blue,
VisibleFromTo = t..t + 0.99*dt,
PointSize = 2*unit::mm
) $ t in [i*dt $ i = 0..imax],
// The orbit of the small planet:
plot::Line2d([Y(t - dt)[9], Y(t - dt)[11]],
[Y(t)[9], Y(t)[11]], Color = RGB::Blue,
VisibleAfter = t
) $ t in [i*dt $ i = 1..imax]
):
//运用"frame by frame"制定三体运动动画
Mupad学习记录3
这节我基于Mupad,对螺旋线作图及其动画做一个探究
及其过程中学习到的控制命令
在这一过程中,学习到了以下几个功能及其命令:
镜头 plot::Camera
排版 Layout = #
标题 Footer, Header
字体 HeaderFont
字体位置 HeaderAlignment
变光滑 AdaptiveMesh
划分 UMesh
多图合并 plot::Scene3d
坐标数据 TicksNumber = None (plot settings)
坐标标示 TicksAt
颜色调整 FillColorFunction, Color=#
原比例尺 Scaling=Constrained
点列 plot::PointList3d
扫面 plot::Sweep
组图 plot::Group3d
点法式平面 plot::Plane
三点式平面 plot::Polygon3d
空间圆 plot::Circle3d
切平面 plot::Parallelogram3d
摆线 WheelRadius
坐标变换 Transformations
这些都是在帮助文档中可以找到详细用法,需要相关命令时查阅帮助文档就可以了
Mupad学习记录4
动画遇到的问题及其解决办法
以下是我在实践中遇到的种种问题,经过反复调试才得到解决,我把这些经验写在这里
1,布局问题
用Layout命令对全是动画或全是静图的Scened2d/3d是奏效的,但是当两者一起,plot命令总是把静图优先放置,导致Horizontal命令失效,这时需要用Layout = Relative命令,自行编制动画位置,方可解决
Mupad学习记录5(关于符号)
Mupad notebook提供了良好的编辑界面,对于想基于该界面,制作报告课件等的用户,了解如何编辑符号公式等就显得很必要。
这一节的帮助文档,详见“Symbols and Special Characters”
Symbol::accentAsterisk 带星号
Symbol::accentTilde 带上弯线
Symbol::accentHat 带上角标
Symbol::accentRightArrow 带向量箭头
Symbol::accentDot 带点
Symbol::accentDoubleDot 带双点
Symbol::accentTripleDot 带三点
Symbol::accentOverBar 带上划线
Symbol::accentUnderBar 带下划线
Symbol::new 调取通用字符(参见Typeset Symbols)
Symbol::subScript 下标
Symbol::subSuperScript 上下标
Symbol::superScript 上标
output::mathText 输出含数学公式的语句
output::ordinal 输出数字序数
output::roman 输出罗马序数
output::tableForm 输出表列
output::tree 输出树状图
修改结果,不缩写化简 Pref::abbreviateOutput(FALSE):
关闭优化字符显示 PRETTYPRINT := FALSE
常见错误分析:
Error: The argument is invalid. [xmlprint::beginElement]
Evaluating: plot
定义的自变量有问题,且只要出现 invalid 一般都说明是拼写出现错误,特别是大小写
Error: The argument 'Umesh = 10' is unexpected. [plot::Curve3d::new]
一般是拼写有误
Error: Unexpected 'identifier'. [line 6, col 1]
缺少冒号
The attribute 'VMesh' in the 'Surface' object must be a positive integer number. [plot]
循环语句i的初始值或末值超出范围,或初值为0,或末值有误
画图结果多出对象,检查最后的plot(中是否多打字母)
相关文章推荐
- 简单理解Hibernate三种状态的概念及互相转化
- 继承
- Eclipse、MyEclipse快捷键大全
- Python2.4.3升级到Python2.7.8
- Python两个内置函数——locals 和globals
- 提供了webservice的wsdl地址,如何生成消费端(客户端),怎么调用已经提供的wsdl接口
- 自我约束
- android系统菜单响应事件
- excel中常用操作
- 慕课网----大话PHP设计模式 六(面向对象编程的基本原则,自动加载config)
- 探索angularjs+requirejs全面实现按需加载的套路
- linux搭建ftp服务器
- SharedPreference在使用过程中有什么注意点?
- 基于HTML5的PACS HTML5图像处理(7)实现客户端JS调整窗宽窗位
- 【网络】Http深入Cookie系列
- jQuery 1.x和jQuery 2.x的最大区别
- LTN154BT08-R03
- iOS网络缓存扫盲篇--使用两行代码就能完成80%的缓存需求
- Unity 几种比较简单的加载动画
- Mob第一章-分享