MATLAB Code for Calculus Assignment
1. Visualizing and Calculating Area of the Region
% Define the curves
y = linspace(0, 2, 100);
x1 = 2*y; % x = 2*y
x2 = (y - 1).^2; % x = (y - 1)^2
% Plot the region
figure;
fill([x1, fliplr(x2)], [y, fliplr(y)], 'cyan');
title('Shaded Region Bounded by x = 2y and x = (y - 1)^2');
xlabel('x'); ylabel('y');
axis equal;
% Calculate the area using integral
area_fun = @(y) 2*y - (y - 1).^2; % Difference between the two curves
area_value = integral(area_fun, 0, 2);
disp(['The area of the region is: ', num2str(area_value)]);
2. Volume of Solid by Revolving a Region
% Define the curves
f_sec = @(x) sec(x); % y = sec(x)
f_tan = @(x) tan(x); % y = tan(x)
% Define the limits
x_min = 0;
x_max = 1;
% Calculate the volume by revolving the region
volume_sec = pi * integral(@(x) f_sec(x).^2, x_min, x_max);
volume_tan = pi * integral(@(x) f_tan(x).^2, x_min, x_max);
% Display the volumes
disp(['Volume generated by revolving y = sec(x): ', num2str(volume_sec)]);
disp(['Volume generated by revolving y = tan(x): ', num2str(volume_tan)]);
3. Function Expansion and Plotting
% Define the original function
f = @(x, y) exp(sin(y));
% Define the expansion point
x0 = 1;
y0 = pi;
% Taylor expansion up to order 5 around the point (1, pi)
syms x y;
f_exp = taylor(exp(sin(y)), [y, pi], 'Order', 6);
% Create mesh grid for plotting
[X, Y] = meshgrid(linspace(0, 2, 100), linspace(0, 2*pi, 100));
% Evaluate original and expanded function
f_original = exp(sin(Y));
f_expanded = double(subs(f_exp, y, Y));
% Plot both in subplots
figure;
subplot(1, 2, 1);
surf(X, Y, f_original);
title('Original Function');
xlabel('x'); ylabel('y'); zlabel('f(x, y)');
subplot(1, 2, 2);
surf(X, Y, f_expanded);
title('Expanded Function up to Order 5');
xlabel('x'); ylabel('y'); zlabel('Expanded f(x, y)');