Get variable out of ode 45
Ältere Kommentare anzeigen
Hi,
I have a function that goes into ode45. In this function multiple variables are calculated to finaly calculate the variable x which is the needed one. This works oke, but to review I would also like to see the other variables calculated, like q12, q23 and q34. I would not only like to see this variables. I also like to make some plots of those values against time, so disp(...) is not a good option. Please if you know how to extract those variables from the function. Let me know.
The function is used to compute water content in different soil layers. This is based on the flow q. Therefore q needs to be calculated, but I would like to know q. Here is the function given where the ode45 is used:
% Calculate content per layer
fh = @(time,x)fflow(time, x, tu, p, Ks, theta_r, theta_s, lambda, n, alpha); % Create function handle to put into ODE-fucntion
[time, xt] = ode45(fh, time, x0); % Compute water content 'x' per layer at time t
The different q values are computed in fflow, part of the code is given for the computation of q12 but for other q values it is the same:
if (TF(1) == 1) && (TF(2) == 0) || ((TF(1) == 1) && (TF(2) == 1)) % First layer saturated, second layer not:
q12 = maxFlowq(Ks(1),lambda(1), n(1), 30); % Maximum flow rate for soil type
elseif ((TF(1) == 0) && (TF(2) == 1)) % First layer not saturated, second layer saturated
q12 = 0;
else % First and second layer not saturated
q12 = -K(1)*((-abs(diff(1))/p(1))+1);
end
% Compute change in water content theta(x)
dx1dt = (qin-q12)/p(1); % Water content difference layer 1
dx2dt = (q12/p(1)-q23/p(2)); % Water content difference layer 2
dx3dt = (q23/p(2)-q34/p(3)); % Water content difference layer 3
dxdt = [dx1dt; dx2dt; dx3dt];
So if possible I would like to have the values for q for every t from this function.I hope you can help me:) Kind regards, Jits
Akzeptierte Antwort
Weitere Antworten (2)
Torsten
am 17 Nov. 2016
1 Stimme
Try the suggestion under
https://de.mathworks.com/matlabcentral/answers/92701-how-do-i-pass-out-extra-parameters-using-ode23-or-ode45-from-the-matlab-ode-Suite
Best wishes
Torsten.
Jan
am 17 Nov. 2016
0 Stimmen
Do not integrate dicontinous functions with Matlab's ODE integrators. They are not designed to handle this correctly and the result can be wrong, dominated by rounding errors or if you are lucky the integration stops with an error:
Kategorien
Mehr zu Ordinary Differential Equations finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!