convert this in matlab please

2 次查看(过去 30 天)
Shazzad  dewan
Shazzad dewan 2017-4-3
回答: Sufiyan 2023-3-30
from gaussQuad2 import *
def f(x,y): return x * y
if _name_ == "__main__": xs = [ 0, 2, 4, 0 ] ys = [ 0, 0, 4, 4 ]
print gaussQuad2( f, xs, ys, 4 )

回答(1 个)

Sufiyan
Sufiyan 2023-3-30
Hi,
You can refer to the code below.
function [Q] = gaussQuad2(f, xs, ys, n)
% Gauss quadrature for double integral over a rectangular domain
% n - number of integration points in each direction
% Define Gauss quadrature weights and nodes
[xs1, ws1] = gauss(n, xs(1), xs(3));
[xs2, ws2] = gauss(n, ys(1), ys(3));
% Compute integral approximation
Q = 0;
for i = 1:n
for j = 1:n
Q = Q + ws1(i)*ws2(j)*f(xs1(i),xs2(j));
end
end
f = @(x,y) x*y;
xs = [0, 2, 4, 0];
ys = [0, 0, 4, 4];
n = 4;
Q = gaussQuad2(f, xs, ys, n);
disp(Q);

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by