필터 지우기
필터 지우기

create dummy variable for different time periods

조회 수: 3 (최근 30일)
susman
susman 2021년 1월 27일
댓글: Star Strider 2021년 1월 27일
I have to create dummy variable for interval1 and interval 2
Suppose,I have equation;
Dependent = exp(1.2 + 0.0099*(Interval1) - 0.0625*(Interval2))* exp (-0.0134*t )
I want to run these equations from time, t = 20 to t = 100
and
interval1 = 1 if t = 20:24 else 0
interval2 = 1 t = 25:100 else 0
I am stuck with the code, please guide me. I want to have an easy solution.

채택된 답변

Star Strider
Star Strider 2021년 1월 27일
Try this:
Dependent = @(t) exp(1.2 + 0.0099*t).*((t>=20) & (t <= 24)) - 0.0625*exp(-0.0134*t ).*((t>=25) & (t<=100));
t = linspace(0, 110, 1E+4);
figure
plot(t, Dependent(t), 'LineWidth',1.25)
grid
xlabel('t')
ylabel('Dependent(t)')
There are some discontinuities because of the way you defined the limits of the segments.
  댓글 수: 2
susman
susman 2021년 1월 27일
Thank you, it worked perfectly in this case. But one more question.
If I have a matrix, in which each cell is definied by a function like above.
for example,
Matrix = [q11 q12 q13; q21 q22 q33; q31 q32 q33]
where each qii is a function like above:
Then if I define each qii, the way you suggested. It would not cause any problem? Like,
q11 = @(t) exp(1.2 + 0.0099*t).*((t>=20) & (t <= 24)) - 0.0625*exp(-0.0134*t ).*((t>=25) & (t<=100));
Star Strider
Star Strider 2021년 1월 27일
My pleasure!
In this example, ‘q11’ defines a vector. I have no idea what the other elements of ‘Matrix’ are, however so long as the dimensions are the same for all of them (vectors the same size as ‘t’) there should be no problems.

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

추가 답변 (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