Integrating a function given multiple points
1 view (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
BhaTTa
on 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)]);
0 Comments
See Also
Categories
Find more on Thermal Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!