Integrating a function given multiple points

3 vues (au cours des 30 derniers jours)
jamie HUGGINS
jamie HUGGINS le 2 Avr 2020
Réponse apportée : BhaTTa le 30 Août 2024
Hi I have been given a function M=Q*c dt where Q is a constant 4. We were given points t=(0,10,20,30,40,50) and corresponding c values that match the t values c=(10,35,55,52,37,34). Im trying to find M total based off these inputs.

Réponses (1)

BhaTTa
BhaTTa le 30 Août 2024
@jamie HUGGINS, to calculate the total value of ( M ) using the given function ( M = Q *c dt ), where ( Q ) is a constant and the values for ( t ) and ( c ) are given as discrete points, you need to perform a numerical integration. This involves summing up the contributions of ( M ) over each time interval (dt). Below is the sample code to achieve this:
% Given data
Q = 4;
t = [0, 10, 20, 30, 40, 50];
c = [10, 35, 55, 52, 37, 34];
% Calculate delta t (time intervals)
delta_t = diff(t); % [10, 10, 10, 10, 10]
% Calculate M for each interval and sum up
M_total = 0;
for i = 1:length(delta_t)
M_i = Q * c(i) * delta_t(i);
M_total = M_total + M_i;
end
% Display the total M
disp(['Total M: ', num2str(M_total)]);

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by