Differential equation/trapezoid rule problem
1 次查看(过去 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!