4

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.

Rody Oldenhuis
  • 37,726
  • 7
  • 50
  • 96
Mack
  • 665
  • 2
  • 11
  • 20

1 Answers1

1

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]
Daniel
  • 36,610
  • 3
  • 36
  • 69
  • Okay. Now I have a question that pertains to ode45. When I pass this function through ode45, with some initial conditions, does ode45 read the derivative -s.*(x-y) as approximating the unknown function x; the same thing being said of -y+r.*x-x.*z and y, and -b.*z+x.*y and z? Also, the vector [s;r;b] is just a vector of parameters. – Mack Mar 09 '14 at 23:48