MATLAB: How to calculate a integral of f=sin(t-D)

integral calculationMATLAB

Hi everybody, I have a question that if I have a function f=sin(t-D), I want to calculate the integral from t=0 to 1 with D=0:0.01:0.1 (10 values of D) So I want to get 10 result for this integral (D=0 to 0.1) How can I do that? I see some example on trap(), but I am not sure how can I apply it to my question. Many thanks. Jianyang

Best Answer

Use the integral function specifying 'ArrayValued',true:
D=0:0.01:0.1;
f = @(t) sin(t-D)
f_int = integral(f, 0, 1, 'ArrayValued',true)
f_int =
Columns 1 through 6
0.4597 0.45126 0.44278 0.43425 0.42568 0.41707
Columns 7 through 11
0.40841 0.39972 0.39098 0.38221 0.37339