define a piecewise function whose parameters change on each segment

4 次查看(过去 30 天)
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