Integrating a function given multiple points

3 Ansichten (letzte 30 Tage)
jamie HUGGINS
jamie HUGGINS am 2 Apr. 2020
Beantwortet: BhaTTa am 30 Aug. 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.

Antworten (1)

BhaTTa
BhaTTa am 30 Aug. 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)]);

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by