Storing ODE Event values that are within a for loop
2 views (last 30 days)
I have created an ode event as
options = odeset('AbsTol',1e-15,'RelTol',1e-13,'Events',@eventfunction);
function [value, isterminal,direction]=eventfunction(t,y)
For a particular parameter set outputs for 'te' and 'ye' are
0.0000 0.0000 0.0000 10.0000 0.0000
In here I don't understand how I get several 'ye' values for one 'te' value? When I plot the solutions the value in which the condition is met is the first value in 'ye' and this is what I am interested in.
What I am trying to do is a sensitivity analysis and for that, I am changing the parameters at a range of values and for each parameter set I want to find the 'te' and 'ye' values that first meet the condition y(1)+y(2)=1 and store these 'te' and 'ye 'values that are obtained at each 'i'th iteration in the for loop in an array.
For this I defined as
and then within the for loop I tried to do as
But then I get an error as index exceeds matrix dimensions and when I tried as b(i)=ye(1) I get an error as "In an assignment A(:) = B, the number of elements in A and B must be the same."
How can I store in each iteration the first time and the value that the event y(1)+y(2)=1 is satisfied?
For some of these parameters it is possible that the ye and te may be empty. That is it may never be y(1)+y(2)=1. When that happens I want 'te' to be set to very large value as 10^5 and 'ye' to be NaN.
Can someone please help me to obtain these 'te' and 'ye' values in each loop iteration.