Clear Filters
Clear Filters

Extract value from function

5 views (last 30 days)
Jose on 5 Sep 2022
Answered: Walter Roberson on 5 Sep 2022
Hello friends, I have this code that return values for dc1dt and dq1dt. But I want to see the values for dc1dz, how can I do that?
function dydt=f(t,y,R,P,epsb,u,LDF1,b1,qm1,c10,Nz,dz,rhop,nco2,T)
%Assign values
for i=2:Nz-1
%main f
dc1dt(i)=-u*dc1dz(i)-(rhop.*R.*T./P *((1-epsb)./epsb).*dq1dt(i));

Accepted Answer

Walter Roberson
Walter Roberson on 5 Sep 2022
Chances are that you do not want to see that.
You are obviously calling an ode*() function. Your function f is going to be evaluated at a series of trial points "near" the current location, in order to predict what the new location should be, and then a cross-check is done to see if the value at another location is "close enough" to a value that the proposed coefficients would predict. For ode45() this involves calculating the function 6 times at each location, with none of the computed locations necessarily making it into the output. If the cross-check was too far away from prediction, then the ode*() goes back and tries again with a smaller step size, another 6 calculations. For any system that cannot be described by a quintic or lower degree polynomial, it is normal for a number of points to be rejected.
Knowing the dc1dz values for a number of trial locations that were never going to make it to output is seldom of benefit.
None of the locations evaluated at necessarily make it to output: the output can end up consisting entirely of predicted values.
For these reasons, most of the time it is much better to call ode45() or whatever normally, getting outputs for various time steps, and then go back and compute the dc1dz values that would be associated with those boundary conditions.
You can use the same function with dc1dz as the second output; loop over the rows of boundary conditions calling the function and capturing the second output... and do whatever with it.

More Answers (0)




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!