define a piecewise function whose parameters change on each segment

7 views (last 30 days)
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.

Answers (1)

Abraham Boayue
Abraham Boayue on 27 May 2018
  1 Comment
hosein Javan
hosein Javan on 27 May 2018
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.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!