Integration of a curve
Afficher commentaires plus anciens
hello, I have a X and y data points. ex: x=[2 3 5]; y=[3 6 3];
after plotting this simple curve, how do I integrate this curve? All the syntax i find on matlab integrates symbolically.
thanks in advance
Réponse acceptée
Plus de réponses (1)
Sara
le 23 Mai 2014
You can use
trapz
1 commentaire
Tayyaba Bano
le 28 Mar 2022
Hi, I need to find the intergal of a curve.
my code involves FOR loop, should I use the trapz command inside the loop or outside the loop to calculate the integral? I tried both but none of them is working.
Moreover, my curve also showing the negative values for the same positive values, how can I avoid these?
I am attaching my curve and the code.
clear all;
close all;
%save 20m3_hr_centre u_original;
%save pos y;
%%load Variables
LS_pos = 'center';
Q = 10;
x_pos = 35; %position of vertical line velocity
%% plot velocity profiles at x_pos
figure(1)
for jj=1:1:10
Q = 10;
PIV(jj)=load(['250mm_',num2str(Q),'m3h_',LS_pos]); %load images
avg(jj) = length(PIV(jj).x); %get data length
%% extract average values
u_avg(:,:,jj) = PIV(jj).u_component{avg(jj),1}(:,:);
v_avg(:,:,jj) = PIV(jj).v_component{avg(jj),1}(:,:);
u_avg_x_pos(:,jj) = PIV(jj).u_component{avg(jj),1}(:,x_pos); % extract u-component at x_pos
x_coord = max(PIV(jj).y{avg(jj),1}(:,x_pos))-PIV(jj).y{avg(jj),1}(:,x_pos); %get and invert vertical coordinate
if jj>6
plot(x_coord,u_avg_x_pos(:,jj)*-1);
else
plot(x_coord,u_avg_x_pos(:,jj));
end
hold on;
end
trapz(x_coord,u_avg_x_pos(:,jj));
xlabel('x [m]');
ylabel(' u ');
%axis([0 0.12 0 1.2])
hold off;
Catégories
En savoir plus sur Numerical Integration and Differentiation dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!