Integration of a curve
이전 댓글 표시
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
채택된 답변
추가 답변 (1개)
Sara
2014년 5월 23일
You can use
trapz
댓글 수: 1
Tayyaba Bano
2022년 3월 28일
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;
카테고리
도움말 센터 및 File Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!