Info

此问题已关闭。 请重新打开它进行编辑或回答。

Using 'if' to evaluate independent variable on DAE

1 次查看(过去 30 天)
Hello Be 't' the independent variable
I can use if to evaluate 't' on ODE:
function f=ODE(t,y)
if t<10 a=10; else a=0; end
f=a;
end
[t,y]=ode15s('ODE',[0,100],1)
I can use if to evaluate 't' on DAE: When the algebraic equation don't depend on the result from if
function f=DAE(t,y)
if t>10 a=0; else a=10; end
b=y(2)+1;
f=[a;b];
end
[t,y]=ode15s(@(t,y) DAE(t,y),[0,100],[1,1],odeset('Mass',[1 0; 0 0]))
But, cant use it when the algebraic equation depend on the result from if
function f=DAE(t,y)
if t>10 a=0; else a=10; end
b=y(2)+a;
f=[a;b];
end
[t,y]=ode15s(@(t,y) DAE(t,y),[0,100],[1,1],odeset('Mass',[1 0; 0 0]))
The solver works until the condition t>10 is reached, then I get this error: Warning: Failure at t=1.000000e+100. Unable to meet integration tolerances without reducing the step size below the smallest value allowed (2.842171e-014) at time t.
The solver reduce the step size when t is near 10, and all sucesive iterations are on t=10, so I can't get the values for t>10.
I guess this happen because the "function if" is a discontinous function, so the solver get this as a singularity and his algorithm can't solve it.
So, my question is: How to use if to evaluate the independent variable, and make the algebraics equations depend on his result avoiding the solver stop working?

回答(1 个)

Jan
Jan 2012-3-31
You can and should use an event, which stops the integration and restart it afterwards. Unfortunately this has to be done manually, because the event functions in Matlab's integrators cannot restart the integration with new parameters.
  1 个评论
Jose
Jose 2012-3-31
Thanks Jan, I'll try that.
I hope to write tomorrow about this solution.

此问题已关闭。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by