# How to get calculated variables from ode function?

1 view (last 30 days)
Alex on 29 Nov 2022
Commented: Jan on 30 Nov 2022
Hi to all
I solve ODE for location and velocity of fluid, using ode23s embeded function. The solution is good. My question is how can I extract variables, which are calculated inside the ode23s? For example, how can I exytract fluid acceleration, a?

Jan on 29 Nov 2022
Edited: Jan on 30 Nov 2022
The function to be integrated computes these values. You have all required inputs as output of ODE23S already. Use them as inputs to your function. Convert the function such, that it accepts matrices as inputs.
tspan = [0, 10];
y0 = [0, 0];
[T, Y] = ode23s(@fcn, tspan, y0);
Z = fcn(T.', Y.').';
plot(T, Y); hold('on');
plot(T, Z(:, 2), 'co'); function dy = fcn(t, y)
dy = [y(2, :); ...
sin(t)]; % [EDITED, T -> t]
end
Jan on 30 Nov 2022
@Alex: I've fixed the typo "T" to "t" and my example does run. So if your code (not mine!) produces an error, post this code. Then the readers can suggest a solution.