Question: (a) Modify the MATLAB Numerical Integration program on Page 2 of the Week 13 PowerPoint slides. Approximate the area under the curve of the function
(a) Modify the MATLAB Numerical Integration program on Page 2 of the Week 13 PowerPoint slides. Approximate the area under the curve of the function
y = 3 x 3 8 x 2 + 4 x + 4 (Range: 0 ? x ? 2)
Have the program calculate the area using the rectangular method (vector approach only) and using MATLABs trapz function (i.e. remove the statements for the scalar approach to the rectangular method). Add statements to find the exact area using the int function of the Symbolic Math Toolbox, and to plot the function using ezplot. Include a grid and axis labels.
Note: int ( f(x), a, b ) calculates the area under the curve y = f(x) for a ? x ? b.
(b) Run the program three times, for N = 2, 4 and 10 intervals.
Submit the modified program, the command window results for the three cases, one copy of the plot and the analytical work.
Hints: Do not use area as a variable name (it is a MATLAB function).
You need dot operators for calculating the y vectors, but do not use dot operators with the functions int and ezplot.
% Area under a Curve % Quarter Circle with Radius 2, Exact area p? = 3.1415 N - input('Enter number of intervals:): w-(b - a) /N: % Rectangular method- scalar approach x-a t w/2: areal -0; for k = 1:N areal -areal + w * y; end Rectangular method- vector approach %x = a + w/ 2 : w: b -w/ 2 ; ty SAELLabs (4 -x^2)) ; %area2 w * sum (y) ; % Use of Trapezoidal method function (trap2) #x=a: w: b; disp('Approximate areas:") disp('Rectangular method -scalar approach' disp (areal) %disp ("Rectangular method- vector approach'); disp (area2) disp'Trapezoidal method function (trapz)'; dis (area3) % Area under a Curve % Quarter Circle with Radius 2, Exact area p? = 3.1415 N - input('Enter number of intervals:): w-(b - a) /N: % Rectangular method- scalar approach x-a t w/2: areal -0; for k = 1:N areal -areal + w * y; end Rectangular method- vector approach %x = a + w/ 2 : w: b -w/ 2 ; ty SAELLabs (4 -x^2)) ; %area2 w * sum (y) ; % Use of Trapezoidal method function (trap2) #x=a: w: b; disp('Approximate areas:") disp('Rectangular method -scalar approach' disp (areal) %disp ("Rectangular method- vector approach'); disp (area2) disp'Trapezoidal method function (trapz)'; dis (area3)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
