define a piecewise function whose parameters change on each segment
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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.
0 commentaires
Réponses (1)
Abraham Boayue
le 27 Mai 2018
Check this link. It provides a vectorized method of implementing a piecewise function. https://www.mathworks.com/matlabcentral/answers/400802-solve-a-system-of-differential-equations-with-a-piecewise-function#answer_320538
Voir également
Catégories
En savoir plus sur Directed Graphs dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!