필터 지우기
필터 지우기

multiple integration with non uniform spacing

조회 수: 4 (최근 30일)
MS
MS 2020년 4월 26일
답변: MS 2020년 4월 29일
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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 4월 26일
편집: Ameer Hamza 2020년 4월 26일
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));

추가 답변 (3개)

MS
MS 2020년 4월 26일
편집: Ameer Hamza 2020년 4월 26일
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
Ameer Hamza
Ameer Hamza 2020년 4월 26일
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 2020년 4월 27일
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

댓글을 달려면 로그인하십시오.


MS
MS 2020년 4월 27일
편집: MS 2020년 4월 27일
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
MS
MS 2020년 4월 29일
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

댓글을 달려면 로그인하십시오.


MS
MS 2020년 4월 29일
Thank you for helping to find it.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by