How to express a piecewise function with time

1 visualizzazione (ultimi 30 giorni)
ZC Song
ZC Song il 29 Apr 2019
Modificato: ZC Song il 29 Apr 2019
Hello,
I would like to express a piecewise function with time. Specifically, I have a time periods of rainfall as well as Intensity for each duration. For example, in the duration of [0,0.1], the intensity will be 0.00365 m/h and in the duration of [0.24 0.45], the intensity is 0.0996 m/h
i_q = -(1/3600)*[0.0365 0.0697 0.0996 0.0493 0.0153]; %FOR STEP LOADING: vector of rainfall intensity steps [m/s]
T_q = 2*3600*[0.1 0.24 0.45 0.78 1]; %FOR STEP LOADING: vector of time intervals of rainfall intensities (2 hrs)
I know for a given piecewise, in this case is 5, the intensity can be expressed by heaciside function and the result is below:
q = @(t) (i_q(1).*(heaviside(t)-heaviside(t-T_q(1)))+ i_q(2).*(heaviside(t-T_q(1))-heaviside(t-T_q(2))) + i_q(3).*(heaviside(t-T_q(2))-heaviside(t-T_q(3))) + i_q(4).*(heaviside(t-T_q(3))-heaviside(t-T_q(4)))...
+ i_q(5).*(heaviside(t-T_q(4))-heaviside(t-T_q(5))));
but now my problem is for arbitary piecewise n? Imaging I have n pairs of Intensity/Duration,how can I compute the q versus time (t)? I tried using other summation funcion but it doesn't work.
i_q = -(1/3600)*I'; %I' contains arbitray numbers which can be import by excel
T_q = time_final*T'; %T' contains arbitray numbers which can be import by excel
n = length(I');
syms n k
q_aux = @(t)(i_q(k).*(heaviside(t-T_q(k-1))-heaviside(t-T_q(k))));
q = symsum(q_aux,k,2,n)+ @(t) (i_q(1).*(heaviside(t)-heaviside(t-T_q(1))));
Does anyone knows how to deal with this problem?

Risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by