Effacer les filtres
Effacer les filtres

convert this in matlab please

2 vues (au cours des 30 derniers jours)
Shazzad  dewan
Shazzad dewan le 3 Avr 2017
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 )

Réponses (1)

Sufiyan
Sufiyan le 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);

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by