multiple integration with non uniform spacing
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Ameer Hamza
le 26 Avr 2020
Modifié(e) : Ameer Hamza
le 26 Avr 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 commentaires
Plus de réponses (3)
MS
le 26 Avr 2020
Modifié(e) : Ameer Hamza
le 26 Avr 2020
13 commentaires
Ameer Hamza
le 26 Avr 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
le 27 Avr 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
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!