Effacer les filtres
Effacer les filtres

Differential equation/trapezoid rule problem

1 vue (au cours des 30 derniers jours)
Doug
Doug le 21 Juil 2014
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

Réponses (1)

Geoff Hayes
Geoff Hayes le 22 Juil 2014
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.

Community Treasure Hunt

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

Start Hunting!

Translated by