define a piecewise function whose parameters change on each segment

조회 수: 5 (최근 30일)
hosein Javan
hosein Javan 2018년 5월 27일
댓글: hosein Javan 2018년 5월 27일
hello I,m trying to write a code to define this piecewise function. the function contains two sub-functions:
v_on(A,B,t) = (define function)
v_off(A,B,t) = (define function)
A & B are parameters given in a matrix and depend on time interval. for example:
A=[1 3 5 2 7]
B=[1 5 8 4 9]
the boundaries which define the time intervals are given in a vector. for example:
tb=1e-3*[1 3 4 5 7]
ok now we must calculate this function:
V(t)=v_on(A(1),B(1),t) if tb(1)<t<tb(2)
V(t)=v_off(A(2),B(2),t) if tb(2)<t<tb(3)
V(t)=v_on(A(3),B(3),t) if tb(3)<t<tb(4)
and so on. I could do it using loops and it works fine. but the code is too complex that if I want to change a few parameters I'd have to review it all over. I was wondering it would be definitely possible by using matrices and arrays.

답변 (1개)

Abraham Boayue
Abraham Boayue 2018년 5월 27일
  댓글 수: 1
hosein Javan
hosein Javan 2018년 5월 27일
I forgot to mention that A,B and tb are very long vectors. the method in the link defines a small number of interval piecewise but here we are dealing with a large number of intervals. thanks for answering.

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

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by