Question

I asked a question regarding how the matlabFunction worked (here), which spurred a question related to the ode45 function. Using the example I gave in my post on the matlabFunction, 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? More specifically, we have the

matlabFunction([s*(y-x);-x*z+r*x-y; x*y-b*z],
            'vars',{t,[x;y;z],[s;r;b]},'file','Example2');

and then we use

[tout,yout]=ode45(@(t,Y,p)  Example2(t,Y,[10;5;8/3]),[0,50],[1;0;0]);

To approximately solve for the unknown functions x,y, and z. How does ode45 know to take the functions, which are defined as variables, [x;y;z] and approximate them? I have an inkling of a feeling that my question is rather vague, but I would just like to know the connection between these things.

Was it helpful?

Solution

The semantics of your commands is that x'(t)=s*(y(t)-x(t)), y'(t)=-x(t)*z(t)+r*x(t)-y(t), and z'(t)=x(t)*y(t)-b*z(t), with the constants you have given for s, r, and b. MATLAB will follow the commands you have given and compute a numerical approximation to this system. I am not entirely sure what you mean by your question,

How does ode45 know to take the functions, […] and approximate them?

That is exactly what you told it to do, and it is the only thing ode45 ever does. (By the time you call ode45, the names x, y, z are completely irrelevant, by the way. The function only cares for a vector of values.) If you are asking about the algorithm behind approximating the solution of an ODE given this way, you can easily find any number of books and lectures on the topic using google or any other search engine.

You may be interested in the function odeToVectorfield, by the way, which simplifies getting these functions from a differential equation written in more traditional form.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top