Azzera filtri
Azzera filtri

multiple integration with non uniform spacing

4 visualizzazioni (ultimi 30 giorni)
MS
MS il 26 Apr 2020
Risposto: MS il 29 Apr 2020
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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Risposta accettata

Ameer Hamza
Ameer Hamza il 26 Apr 2020
Modificato: Ameer Hamza il 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));

Più risposte (3)

MS
MS il 26 Apr 2020
Modificato: Ameer Hamza il 26 Apr 2020
Hi Ameer,
Thank you very much. I need two modfications in the code.
1, I need to apply the same code through loop and save result as seperate file.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:numel(avg_mat)
writematrix(avg_mat{i}, ['avg_val_' num2str(i)]);
R = avg_mat{i}(:,1);
C = avg_mat{i}(:,2);
F = avg_mat{i}(:,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));
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2, I want to choose min(R) and max(R) values for each and every file in the for loop as shown in the atttachment figure.
thanks
  13 Commenti
Ameer Hamza
Ameer Hamza il 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
Ameer Hamza il 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

Accedi per commentare.


MS
MS il 27 Apr 2020
Modificato: MS il 27 Apr 2020
Thanks a bunch. Since my u and v values has got alot of 'NANs' the out put seen as 'NANs' . is there a way to avoid NANs by using any logical operator. Please include a way to add logical in the code.
  8 Commenti
MS
MS il 29 Apr 2020
your help is major for my project. now, i need help to plot (r(i),c(i)) as a rectangle for each file. can you help me to add a line.
navg = numel(avg_mat);
r = cell(navg,1);
c = cell(navg,1);
maxi = 90;
%this code is designed to handle odd navg as well as even
t1 = linspace(0, maxi, ceil(navg/2)+1);
t2 = linspace(maxi, 0, navg - length(t1)+2);
tvals = [t1(2:end), t2(2:end)];
results = zeros(navg,1);
Fg = cell(navg,1);
for i = 1:navg
writematrix(avg_mat{i}, ['avg_val_' num2str(i)]);
R = avg_mat{i}(:,1);
C = avg_mat{i}(:,2);
F = avg_mat{i}(:,5);
r{i} = linspace(min(R), max(R), 1000) * cosd(tvals(i));
c{i} = linspace(min(C), max(C), 1000) * sind(tvals(i));
[Rg, Cg] = meshgrid(r{i}, c{i});
tg = griddata(R, C, F, Rg, Cg);
end

Accedi per commentare.


MS
MS il 29 Apr 2020
Thank you for helping to find it.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by