double integral by a single variable by simpsons method

조회 수: 6 (최근 30일)
Namira
Namira 2016년 9월 30일
댓글: elias GR 2016년 10월 3일
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