0% found this document useful (0 votes)
24 views3 pages

MATLAB Calculus Visualizations and Calculations

The document contains MATLAB code for a calculus assignment that includes visualizing and calculating the area of a region bounded by two curves, computing the volume of solids generated by revolving functions, and performing a Taylor expansion of a function. It provides detailed steps for plotting the region, calculating areas and volumes, and visualizing both the original and expanded functions. The code includes comments for clarity and uses various MATLAB functions for calculations and visualizations.

Uploaded by

vaibhav22na
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views3 pages

MATLAB Calculus Visualizations and Calculations

The document contains MATLAB code for a calculus assignment that includes visualizing and calculating the area of a region bounded by two curves, computing the volume of solids generated by revolving functions, and performing a Taylor expansion of a function. It provides detailed steps for plotting the region, calculating areas and volumes, and visualizing both the original and expanded functions. The code includes comments for clarity and uses various MATLAB functions for calculations and visualizations.

Uploaded by

vaibhav22na
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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)');

You might also like