multiple integration with non uniform spacing
10 views (last 30 days)
Show older comments
I need help to find an area intergeral of the attached file(av_val_1) with 10 columns.
where 1st column = R , second column = C, Fifth column = F(R,C).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
R= avg_val_1(:,1);%first columsn = r axis
C = avg_val_1(:,2);%second column = c axis
F = avg_val_1(:,5);%fifth column = F(r,c)
I = trapz(C,trapz(R,F,2)); %area integeral of the total area. This line is wrong.
And
q = integral2(F(r,c),Rmin,Rmax,Cmin,Cmax) %area integeral of the particular area portion. This line is wrong. please see attached figure for reference
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0 Comments
Accepted Answer
Ameer Hamza
on 26 Apr 2020
Edited: Ameer Hamza
on 26 Apr 2020
You first need to convert the data into a grid before applying the trapz twice
x = load('avg_val_1.txt');
R = x(:,1);
C = x(:,2);
F = x(:,5);
r = linspace(min(R), max(R), 1000);
c = linspace(min(C), max(C), 1000);
[Rg, Cg] = meshgrid(r, c);
Fg = griddata(R, C, F, Rg, Cg);
result = trapz(c, trapz(r, Fg, 2));
0 Comments
More Answers (3)
MS
on 26 Apr 2020
Edited: Ameer Hamza
on 26 Apr 2020
13 Comments
Ameer Hamza
on 26 Apr 2020
Sorry, I don't have much expertise in multivariate calculus.
Isn't this just two independent integrals. You can do it like this.
trapz(r,u) + trapz(c,v)
Ameer Hamza
on 27 Apr 2020
For simple integrals, you don't need to use geiddata. You can do something like this
%%%%%%%%%%%%%%%%
for i=1:numel(avg_mat)
writematrix(avg_mat{i}, ['avg_val_' num2str(i)]);
R = avg_mat{i}(:,1);
C = avg_mat{i}(:,2);
u = avg_mat{i}(:,3);
v = avg_mat{i}(:,4);
line_integeral(i)= trapz(R,u) + trapz(C,v)
% fseg = interp2(Rg,Cg,Fg,rcseg(:,1),rcseg(:,2)); %%this line is wrong, The number of input coordinate arrays does not equal the number of dimensions (NDIMS) of these arrays%%%%
% d = cumsum([0;sqrt(sum(diff(rcseg).^2,2))]);
% line_integeral(i) = trapz(d,fseg)
end
See Also
Categories
Find more on Matrices and Arrays 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!