Matlab ode solver - putting condition in function

조회 수: 11 (최근 30일)
kkh1897
kkh1897 2020년 12월 6일
댓글: Ameer Hamza 2020년 12월 6일
I use ode23s solver
and the results show that variables oscillate around zero plus and minus.
I want to fix the variables to zero when they first go under zero.
ode23s solver can't use odeset 'NonNegative' option,
so we should have to put some condition in the function.
Please give me help.

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 12월 6일
편집: Ameer Hamza 2020년 12월 6일
The easiest option might be to do this after getting the solution from ode23s. For example
[t, y] = ode23s(..)
idx = find(y<0, 1);
y(idx:end) = 0
This assumes that your ODE is first-order and y is a column vector.
  댓글 수: 4
kkh1897
kkh1897 2020년 12월 6일
I sent you a email. Thank you
Ameer Hamza
Ameer Hamza 2020년 12월 6일
This is the code with ode45(). However, due to some reason, the result is different as compared to dsolve(). I am not sure why.
ode = @(t, x) [x(2);
-sign(x(1)+x(2))];
IC = [1; 0];
tspan = [0 5];
ode(ode, tspan, IC)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by