# Change parameter value during ode15s solution

조회 수: 3(최근 30일)
gorilla3 2018년 8월 23일
댓글: gorilla3 2018년 8월 23일
Hi,
I'm solving a set of differential equations and I'd like to change the value of a constant (Pin) at a specific time during the solution. Meaning that during the timespan, I'd like to change the value of Pin. So it time>10, Pin=70, else Pin=60.
This is how I formulated it but it's not working:
tspan=0:0.1:100;
cond= [...];
[t,y] = ode15s(@fun2,tspan, cond,[]);
function dydt= fun2(t,y)
for i=1:1:length(tspan)
if tspan(i)<10
Pin=60;
else
Pin=70;
end
end
...
end

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

### 채택된 답변

Torsten 2018년 8월 23일
function dydt= fun2(t,y)
...
if t<10
Pin=60;
else
Pin=70;
end
...
Better use the EVENT-facility of the ODE solvers than the if-construction.
Best wishes
Torsten.
##### 댓글 수: 3표시숨기기 이전 댓글 수: 2
gorilla3 2018년 8월 23일
thanks for the suggestion but this gives me an "instantaneous" response. Meaning that the solutions for (Pin=60, t<10) and (Pin=70, t>10) are just joined together but there's no information on the transition / adaptation of the system to this change. (see fig instant.jpg)
If, instead, I solve it all in one go, using the if-else within the function I can see the transition yet it's a linear jump. What I meant with my initial question is: is there a way to get more data points so that the plot would be a curve rather than these coarse lines? Indeed, the ode15s solver provides me only with 44 solution points, despite the tspan being of 1001. (see fig 10sreponse.jpg)

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

### 범주

Find more on Ordinary Differential Equations in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by