Differential equation/trapezoid rule problem

조회 수: 8 (최근 30일)
Doug
Doug 2014년 7월 21일
답변: Geoff Hayes 2014년 7월 22일
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개)

Geoff Hayes
Geoff Hayes 2014년 7월 22일
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.

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by