Storing ODE Event values that are within a for loop

1 次查看(过去 30 天)
I have created an ode event as
options = odeset('AbsTol',1e-15,'RelTol',1e-13,'Events',@eventfunction);
[t,y,te,ye,ie]=ode45(@Equations(t,y),0:time,[a0,b0,c0,d0],options);
function [value, isterminal,direction]=eventfunction(t,y)
value=y(1)+y(2)-1;
isterminal=1;
direction=0;
For a particular parameter set outputs for 'te' and 'ye' are
te =
1.8555e+03
ye =
1.0e+06 *
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
a=zeros(1,1000);
b= zeros(1,1000);
and then within the for loop I tried to do as
a(i)=te
b(i)=ye
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.

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by