Clear Filters
Clear Filters

convert this in matlab please

2 views (last 30 days)
Shazzad  dewan
Shazzad dewan on 3 Apr 2017
Answered: Sufiyan on 30 Mar 2023
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 )

Answers (1)

Sufiyan
Sufiyan on 30 Mar 2023
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);

Categories

Find more on Programming in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!