double integral by a single variable by simpsons method

6 次查看(过去 30 天)
I want to calculate the double integral by a single variable by simpsons method. This is my code. I have a function f(x,y). I want to integrate it wrt x and then it integrate again wrt x. First I used the code for first integration. Then the result I put as a function f(x,y) and integrate again. I am confused about my code. Is it the right way to solve it? Or is there any simplest way to solve it?
function [s] = simprl(f,a,b,n) % f is the function to be integrated; a = initial value of the interval; b = final value of the interval; n = No. of subintervals
% The function implements the Simpson's Rule
h = (b-a)./n;
s1 = 0; % The variable s1 is initialised to 0.
s2=0; % The variable s2 is initialised to 0.
% loop for odd values in the range
for k = 1:n/2; % The index variable k starts at 1, then increases in steps of 1 until it reaches n/2.
x = a + h*(2*k-1);
s1 = s1+feval(f,x); % Each time through the loop the value of feval(f,x) is added to s1.
end
% loop for even values in the range
for k = 1:(n/2 - 1);
x = a + h*2*k;
s2 = s2+feval(f,x);
end
% Final result of integration where odd values are multiplied by 4 and even values are multiplied by 2
s = h*(feval(f,a)+feval(f,b)+4*s1+2*s2)/3;
  1 个评论
elias GR
elias GR 2016-10-3
What do you mean by "double integral by a single variable by simpsons method". Can you give the analytic expression of the integral that you want to calculate? Furthermore, you say that "I want to integrate it wrt x and then it integrate again wrt x.". What wrt is? Why do you want to integrate twice?

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Numerical Integration and Differential Equations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by