理解matlab函数 [英] Understanding matlabFunction
问题描述
在我的计算物理类中,我一直使用 matlabFunction
,并且我希望有人能够帮助我理解这个命令究竟发生了什么( matlabFunction
一个命令?)。我已阅读 MathWorks网站提供的关于 matlabFunction
,但希望有所澄清。例如,我们处理了Lorenz方程组,这是一个混沌系统。这是一个微分方程组:
dx / dt = s *(yx),dy / dt = -x * z + r * xy,dz / dt = x * yb * z。
我们使用 matlabFunction
p>
matlabFunction([s *(yx); - x * z + r * xy; x * yb * z],...
'vars',{t,[x; y; z],[s; r; b]},...
'file','Example2');
我知道 [s *(yx); - x * z + R * XY; x * yb * z]
是包含我们未知函数的列向量(在这种情况下,它们是时间的导数),我们用它来近似函数x(t),y(t )和z(t)与 ode45
。
我的问题是, [s *(y-x); - x * z + r * x-y; x * y-b * z]
与有关{t,[x; y; z],[s; r; b]}
?显然这个顺序很重要,但我不太明白这一点。如果我知道两者之间的关系,我想我会理解这一点。
如果您觉得我没有提供足够的信息,请告诉我。 / div>
您的代码(不包括文件
- 参数)会生成以下输出:
matlabFunction([s *(yx); - x * z + r * xy; x * yb * z],'vars',{t,[x; y; z],[s; r; b]})
ans =
@(t,in2,in3)[ - in3(1,:)。*(in2(1,:) - 平方英寸(2,:)。); - 英寸2(2:)+立方英寸(2,:)*英寸2(1,:) - 英寸2(1,:)*英寸2(3:); - 立方英寸(3 ,:)。* in2(3,:)+ in2(1,:)。* in2(2,:)]
单元格 {t,[x; y; z],[s; r; b]}
定义函数的第一个输入参数是 T
。第二个输入参数 in2
是一个包含 [x; y; z]
的3元素向量,第三个输入参数in3是一个包含 [s; r; b]
的3元素向量,将输出与以下内容进行比较,以查看你的符号变量和输入参数之间的关系:
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $> matlab函数([s *(yx); - x * z + r * xy; x * yb * z],'vars',{t,x,y,z,s,r,b})
ans =
@(t ,x,y,z,s,r,b)[ - s。*(xy); - y + r。* xx。* z; -b。* z + x。* y]
code>
I have been using matlabFunction
rather extensively in my computational physics class, and I was hoping someone could help me understand what exactly is going on with this command (is matlabFunction
a command?). I have read what the MathWorks website provides regarding matlabFunction
, but was hoping for some clarification.
For instance, we dealt with Lorenz equations, a chaotic system. This is a system of differential equations:
dx/dt = s*(y-x), dy/dt = -x*z+r*x-y, dz/dt = x*y-b*z.
We used matlabFunction
as such:
matlabFunction([s*(y-x);-x*z+r*x-y; x*y-b*z],...
'vars', {t,[x;y;z],[s;r;b]},...
'file', 'Example2');
I understand that [s*(y-x);-x*z+r*x-y; x*y-b*z]
is a column vector containing our unknown functions (in this case, they are derivatives with respect to time), which we use to approximate the functions x(t), y(t), and z(t) with ode45
.
My question is, how is [s*(y-x);-x*z+r*x-y; x*y-b*z]
related to {t,[x;y;z],[s;r;b]}
? Evidently the order matters, but I don't quite understand this. I think I would understand this if I knew the relationship between the two.
If you feel that I have not provided enough information, please let me know.
Your code (excluding the file
-parameter) generates the following output:
matlabFunction([s*(y-x);-x*z+r*x-y; x*y-b*z],'vars',{t,[x;y;z],[s;r;b]})
ans =
@(t,in2,in3)[-in3(1,:).*(in2(1,:)-in2(2,:));-in2(2,:)+in3(2,:).*in2(1,:)-in2(1,:).*in2(3,:);-in3(3,:).*in2(3,:)+in2(1,:).*in2(2,:)]
The cell {t,[x;y;z],[s;r;b]}
defines that the first input argument of the function is t
. The second input argument in2
is a 3 element vector containing [x;y;z]
and the third input argument in3 is a 3 element vector containing [s;r;b]
Compare the output to the following, to see the relation between your symbolic variables and input arguments:
matlabFunction([s*(y-x);-x*z+r*x-y; x*y-b*z],'vars',{t,x,y,z,s,r,b})
ans =
@(t,x,y,z,s,r,b)[-s.*(x-y);-y+r.*x-x.*z;-b.*z+x.*y]
这篇关于理解matlab函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!