How to calculate the area under the curve with data given on an excel file, and not using the function "trapz"?
54 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Andres Gustavo Ambriz Gudiel
il 3 Ago 2021
Commentato: Wan Ji
il 10 Ago 2021
Create a MATLAB program to calculate the area under the curve for the strain-stress. The goal of the project is to have a MATLAB script that automatically reads the experimental data set. The MATLAB script must not use native functions like “trapz” in the calculation of the area. The goal is to calculate the area under the stress-strain curve.
4 Commenti
James Tursa
il 3 Ago 2021
I meant are you supposed to write your own area calculator function from scratch? (be it Euler or trapezoid or whatever)
Risposta accettata
Scott MacKenzie
il 3 Ago 2021
Modificato: Scott MacKenzie
il 3 Ago 2021
f = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/702117/Steel6150Tens.csv';
T = readtable(f);
T(end,:) = []; % remove last row, outlier
x = T.Strain;
y = T.Stress;
plot(x,y)
% compute area the hard way
a0 = 0;
for i=2:length(x)
a0 = a0 + (x(i)-x(i-1)) * (y(i)+y(i-1))/2;
end
fprintf('Area: %f\n', a0);
% verify result using trapz
a1 = trapz(x, y);
fprintf('Area using trapz: %f\n', a1);
8 Commenti
Wan Ji
il 10 Ago 2021
By using 'type trapz' command, one can see the vectorized trapz method, the code is simplified as:
z = diff(x,1,1).' * (y(1:end-1,:) + y(2:end,:))/2;
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!