How to compute the double integral over dx and dy?
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Kalasagarreddi Kottakota
el 3 de Abr. de 2023
Comentada: Star Strider
el 3 de Abr. de 2023
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);
0 comentarios
Respuesta aceptada
Star Strider
el 3 de Abr. de 2023
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
rowInt = trapz(columnInt) % Integrate Column Integrals
totalInt = trapz((trapz((a-b).^2))) % Both In One Line
.
2 comentarios
Star Strider
el 3 de Abr. de 2023
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
rowInt = trapz(y,columnInt) % Integrate Column Integrals
totalInt = trapz(y,trapz(x,(a-b).^2)) % Both In One Line
.
Más respuestas (2)
Samyuktha
el 3 de Abr. de 2023
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!
0 comentarios
Torsten
el 3 de Abr. de 2023
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))
I2 = trapz(x,trapz(y,F,1))
0 comentarios
Ver también
Categorías
Más información sobre Numerical Integration and Differentiation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!