MATLAB实现二重积分计算
太原理工大学中外合作办学-数值分析作业题
1. Question 1: (50 marks)
Evaluate the following double integral. Note that the upper y boundary is a function of x
(a)Manually solve this question by using one Simpson 1/3 rule in the x-direction and two Simpson 1/3 rules in the y-direction. (15 marks)
(It is requested to show the detailed calculation procedure in your report, including the intervals, meshing, function values at each node, and integral for x and y, etc)
(b)Develop a MATLAB M-file based on the Simpson 1/3 rules for evaluation of the double integral of the above function with any number of Simpson 1/3 rules in the x- and y-directions. Note the number of Simpson 1/3 may be different in the x- and y-directions
Then, use the developed code to calculate the above double integral by different numbers of Simpson 1/3 rules until an accurate result is achieved. (25 marks)
(The M-file must be well commented and included in the report, and the developed code must be submitted for checking. You need to try different numbers of Simpson 1/3 rules in x- and y-directions until an accurate result is achieved. And justify why the final result is acceptable).
©Choose a proper MATLAB built-in function and develop an M-file script to calculate the above double integral.
(10 marks)
(The M-file must be well commented and included in the report, and the developed code must be submitted for checking. You are requested to compare the results by built-in function with the data obtained by the developed code. )
- 问题1解答
(a)Normal dual integration
Simpson 1/3rule:
(b) 解答
The code implementation using matlab is as follows.
% Define the integrand
f = @(x, y) x^2 - 2*y^2 + x*y^3;
% Define the integration region
x_start = 0;
x_end = 2;
y_start = -1;
y_end = @(x) 0.5 + 0.5*x;
% Define the number of intervals for the Simpson 1/3 rule in the x and y directions
num_intervals_x = 1;
num_intervals_y = 2;
% Calculate the step sizes in the x and y directions
h_x = (x_end - x_start) / num_intervals_x;
% Initialize the integration result
result = 0;
% Perform double integration using Simpson's 1/3 rule
for i = 1:num_intervals_x
% Calculate the start and end values of the current x interval
x1 = x_start + (i-1) * h_x;
x2 = x_start + i * h_x;
% Calculate the number of intervals for the Simpson 1/3 rule in the y direction for the current x interval
num_intervals_y = 10 + i;
% Calculate the step size in the y direction
h_y = (y_end(x2) - y_start) / num_intervals_y;
% Use Simpson's 1/3 rule to calculate the double integral for the current x interval
for j = 1:num_intervals_y
% Calculate the start and end values of the current y interval
y1 = y_start + (j-1) * h_y;
y2 = y_start + j * h_y;
% Calculate the area of the current region
area = (x2 - x1) * (y2 - y1);
% Calculate the function values at the boundary points
f_x1y1 = f(x1, y1);
f_x2y1 = f(x2,<