Understanding matlabFunction

I used matlabFunctioncomputational physics quite widely in my class, and I was hoping that someone could help me understand what exactly is happening with this team (is there a matlabFunctionteam?). I read what the MathWorks website provides relatively matlabFunction, but was hoping for some clarification.

For example, we were dealing with Lorentz 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 matlabFunctionas 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]this is a column vector containing our unknown functions (in this case they are time derivatives), which we use to approximate the functions x (t), y (t) and z (t) s ode45.

My question is: how [s*(y-x);-x*z+r*x-y; x*y-b*z]is it related to {t,[x;y;z],[s;r;b]}? Obviously, order matters, but I don't quite understand it. I think I would understand this if I knew the relationship between them.

If you feel that I have not provided sufficient information, please let me know.

+4
source share
1 answer

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 what is the first input argument to the function t. The second input argument in2is a three-element vector containing [x;y;z], and the third input argument in3 is a three-element vector containing[s;r;b]

, :

    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]
+1

Source: https://habr.com/ru/post/1530885/


All Articles