double integral by a single variable by simpsons method
5 ビュー (過去 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
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 Center および File 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!