Differential equation/trapezoid rule problem
조회 수: 8 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (1개)
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.
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!