How can I use funtions defined in a column vector individually?
Show older comments
I am looking to solve a problem using ode45 and Runge-Kutta method. For ode45 I hav defined the function as follows.
odefun = @(x,T) [T(2); -a*(Ta-T(1))];
I want to use each of the individual function defined in each row in my Runge-Kutta function. Can I extract them from the odefun above or do I need to define them separately again as two anonymous function?
2 Comments
Jan
on 11 Jul 2021
What does this mean:
"I want to use each of the individual function defined in each row in my Runge-Kutta function."
If you create your own Runge-Kutta method, prefer to evaluate the function exactly as ODE45 does it. Do not adjust the integrator to the number of elements the function has, because it is much easier to program it generally.
Divyaprakash
on 11 Jul 2021
Edited: Divyaprakash
on 11 Jul 2021
Accepted Answer
More Answers (1)
Please help me understand how the ode45 routine acceses the rows of odefun individually.
It doesn't, not the way I think you mean it.
odefun = @(x,T) [T(2); -a*(Ta-T(1))];
This is not two "individual function[sic] defined in each row in my Runge-Kutta function". This is one anonymous function that accepts two inputs, x and T (which must have at least two elements) and returns a vector as its output. That vector has at least two elements assuming neither a nor Ta were empty, but still just one function.
You could call your odefun with two inputs and then index into the vector that odefun returns, but that does not make odefun two functions in any way, shape, or form.
f = @(x, y) [sind(x); cosd(y)];
z = f(45, 135)
z(2) - cosd(135)
Because of the way f is constructed and called, z(2) is cosd(135).
1 Comment
Divyaprakash
on 11 Jul 2021
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!