Question
Code adaptive refinement for the Rectangle, Trapezium and Simpson's Rules, where the number of intervals in x and y directions are progressively increased from 8
Code adaptive refinement for the Rectangle, Trapezium and Simpson's Rules, where the number of intervals in x and y directions are progressively increased from 8 to 80 in steps of 2. The following types of refinement should be implemented for each rule: a. Onlv increase the number of intervals in the x direction in steps of 2, leaving the number of intervals in the y direction constant at 8. b. Only increase the number of intervals in the y direction in steps of 2, leaving the number of intervals in the x direction constant at 8. Simultaneously increase the number of intervals in the x and y direction from 8 to 80 in steps of 2. Show your Matlab code.
Please answer using this template
close all; clearvars; clc;
%define integration method
sel_meth = -1;
disp('Integration Method:');
disp('1) Rectangular, 2) Trapezium, 3) Simpsons 4) Gaussian');
%ensure that correct number is provided
while (sel_meth~=1 && sel_meth~=2 && sel_meth ~=3 && sel_meth ~=4 )
sel_meth = input('Please Select integration method: 1,2,3 or 4 ');
end
N = -1;
disp('Set Number of intervals in x direction, or of Gauss points:');
while (N<1 || uint8(N)~=N ) % so N has to be < 255 (2^8=256-> max unsigned 8-bit integer : 255)
N = input('Please provide a positive integer ');
end
M = -1;
disp('Set Number of intervals in y direction, or of Gauss points:');
while (M<1 ||uint8(M)~=M ) % also M <255
M = input('Please provide a positive integer ');
end
x_min=inf; y_min=inf;
disp('Set the lower limits for integration:');
while (isinf(x_min) && isnumeric(x_min))
x_min = input('In the x direction: ');
end
while (isinf(y_min) && isnumeric(y_min))
y_min = input('In the y direction: ');
end
x_max=-inf; y_max=-inf;
disp('Set the upper limits for integration:');
while (isinf(x_max) && isnumeric(x_max) && (x_max x_max = input('In the x direction: '); end while (isinf(y_max) && isnumeric(y_max) && (y_max y_max = input('In the y direction: '); end %x_min=-1; x_max=0; y_min=0; y_max=2; switch sel_meth case 1 INTEGRAL=Rect_2D_tut_analytic(@fun1,x_min,x_max,y_min,y_max,N,M); METHOD= 'Rectangle'; case 2 INTEGRAL=Trap_2D_tut_analytic(@fun1,x_min,x_max,y_min,y_max,N,M); METHOD = 'Trapezium'; case 3 INTEGRAL=simp_2D_tut_analytic(@fun1,x_min,x_max,y_min,y_max,N,M); METHOD = 'Simpsons'; case 4 INTEGRAL=Gauss_2D_tut_analytic(@fun1,x_min,x_max,y_min,y_max,N,M); METHOD = 'Gauss'; end
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started