フィルターのクリア

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 Center および File ExchangeProgramming についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by