Integrating a function given multiple points

3 次查看(过去 30 天)
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.

回答(1 个)

BhaTTa
BhaTTa 2024-8-30
@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)]);

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by