필터 지우기
필터 지우기

How to compute the double integral over dx and dy?

조회 수: 2 (최근 30일)
Kalasagarreddi Kottakota
Kalasagarreddi Kottakota 2023년 4월 3일
댓글: Star Strider 2023년 4월 3일
Hi, Can someone help me to how to code this equation in matlab? Let x and y are axis of a plane. dx and dy are increments. I have values of a and b at each coordinate(x,y) as shown in the below code.
clear all; close all;clc;
% Let
dx = 0.1;
x = -0.5:dx:0.5;
dy = 0.1;
y = -0.5:dx:0.5;
N = length(x);
a = randn(N,N);
b = randn(N,N);

채택된 답변

Star Strider
Star Strider 2023년 4월 3일
You are integrating matrices, so use trapz (or cumtrapz, depending on the result you want) once in each dimension —
% clear all; close all;clc;
% Let
dx = 0.1;
x = -0.5:dx:0.5;
dy = 0.1;
y = -0.5:dx:0.5;
N = length(x);
a = randn(N,N);
b = randn(N,N);
columnInt = trapz((a-b).^2) % Column Integrals
columnInt = 1×11
19.6448 26.9404 10.3535 10.6369 19.7843 13.8794 7.4786 12.1139 10.1436 22.0933 19.0884
rowInt = trapz(columnInt) % Integrate Column Integrals
rowInt = 152.7905
totalInt = trapz((trapz((a-b).^2))) % Both In One Line
totalInt = 152.7905
.
  댓글 수: 2
Torsten
Torsten 2023년 4월 3일
Don't forget to scale the results by dx*dy.
Star Strider
Star Strider 2023년 4월 3일
I initially forgot that. Assuming ‘x’ defines the columns and ‘y’ defines the rows —
% clear all; close all;clc;
% Let
dx = 0.1;
x = -0.5:dx:0.5;
dy = 0.1;
y = -0.5:dx:0.5;
N = length(x);
a = randn(N,N);
b = randn(N,N);
columnInt = trapz(x,(a-b).^2) % Column Integrals
columnInt = 1×11
3.2512 1.1639 1.0265 1.5750 2.4845 1.1630 3.4526 2.8748 1.7902 0.9262 3.7454
rowInt = trapz(y,columnInt) % Integrate Column Integrals
rowInt = 1.9955
totalInt = trapz(y,trapz(x,(a-b).^2)) % Both In One Line
totalInt = 1.9955
.

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

추가 답변 (2개)

Samyuktha
Samyuktha 2023년 4월 3일
Hi Kalasagarreddi,
I understand that you want to compute a double integral.
You can do this with the help of 'integral2' command. Please refer to the following documentation link for information on the syntax of 'integral2'.
Hope this helps!

Torsten
Torsten 2023년 4월 3일
dx = 0.1;
x = -0.5:dx:0.5;
dy = 0.1;
y = -0.5:dx:0.5;
N = length(x);
a = randn(N,N);
b = randn(N,N);
F = (a-b).^2;
% Use one of the following approximations for the integral
I1 = trapz(y,trapz(x,F,2))
I1 = 2.0996
I2 = trapz(x,trapz(y,F,1))
I2 = 2.0996

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by