Filter löschen
Filter löschen

convert this in matlab please

2 Ansichten (letzte 30 Tage)
Shazzad  dewan
Shazzad dewan am 3 Apr. 2017
Beantwortet: Sufiyan am 30 Mär. 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 )

Antworten (1)

Sufiyan
Sufiyan am 30 Mär. 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);

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by