フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Using 'if' to evaluate independent variable on DAE

2 ビュー (過去 30 日間)
Jose
Jose 2012 年 3 月 31 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
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