Differential equation/trapezoid rule problem

Please, any guidance from anyone?
Attempt that is definitely wrong:
t_plotted = [0 1 5.5 10 12 14 16 18 20 24];
c = [1 1.5 2.3 2.1 4 5 5.5 5 3 1.2];
delta_t = 0.1;
t = 0:delta_t:24;
q = 20 + 10*sin((2*pi/24)*(t-10));
for i = 2:length(q)
for j = 2:length(c)
c_avg(i) = ((q(i) - q(i-1))*(c(j) - c(j-1))*delta_t) / (q(i) - q(i-1))*delta_t;
end
end

回答(1 个)

Your t differs from that which is defined in the link that you provided. I think that you are supposed to use what you have defined as t_plotted instead.
See trapz which is the MATLAB function for the trapezoid rule and trapezoidal rule which outlines the algorithm.
Use this algorithm, instead of the double for loop, to calculate the two integrals (the numerator and the denominator) of the flow-weighted average concentration over the 24 hour period using the t_plotted and c defined as above.

类别

帮助中心File Exchange 中查找有关 Numerical Integration and Differentiation 的更多信息

提问:

2014-7-21

Community Treasure Hunt

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

Start Hunting!

Translated by