Admin 08 Jun 2026 05:40

 

MATLAB Notes for Calculus 2

Introduction

MATLAB is a powerful computational tool that can significantly enhance your understanding and application of Calculus 2 concepts. These notes provide a practical guide for using MATLAB to solve problems related to integration techniques, sequences and series, parameterized curves, and multivariable calculus.

Getting Started with MATLAB

Basic Interface

The MATLAB interface consists of several key components:

  • Command Window: Where you enter commands and see immediate results
  • Workspace: Displays all variables currently in memory
  • Current Folder: Shows files in your working directory
  • Editor: For creating and editing script files

Basic Commands

% Variablesx = 5;               % Semicolon suppresses outputy = pi;              % Built-in constants% Basic operationsz = x + y;w = sin(x);          % Trigonometric functions% Displaying resultsdisp(z);             % Display valuefprintf('z = %f\n', z); % Formatted output% Help and documentationhelp sin             % Help on specific functiondoc sin              % Documentation for sin function

Integration Techniques

Symbolic Integration

For indefinite and definite integrals, MATLAB's Symbolic Math Toolbox provides powerful capabilities:

% Define symbolic variablesyms x% Indefinite integralF = int(sin(x), x)           % Returns -cos(x)% Definite integralintegral_value = int(x^2, x, 0, 2)  % Returns 8/3% Improper integralsimproper = int(1/x, x, 1, inf)      % Returns Inf% Multiple integralsdouble_int = int(int(x*y, y, 0, 1), x, 0, 2)  % Returns 1

Note: When using symbolic integration, you can use simplify() to simplify the result and pretty() to display it in a more readable format.

Numerical Integration

For functions without simple antiderivatives or experimental data:

% Define a function handlef = @(x) exp(-x.^2);% Numerical integrationresult = integral(f, 0, 1)    %  e dx% Multiple integrationf2 = @(x,y) x*y;result2 = integral2(f2, 0, 1, 0, 2)  %  x*y dy dx

Example: Calculate the arc length of y = sin(x) from 0 to :

f = @(x) sqrt(1 + cos(x).^2);arc_length = integral(f, 0, pi);

This returns approximately 3.8202.

Sequences and Series

Sequences

MATLAB can generate and analyze numerical sequences:

% Generating sequencesn = 1:10;a = 1./n;                    % a_n = 1/nb = (n+1)./n;                % b_n = (n+1)/n% Plotting sequencesfigure;subplot(2,1,1); stem(n, a);title('Sequence a_n = 1/n');xlabel('n'); ylabel('a_n');subplot(2,1,2); stem(n, b);title('Sequence b_n = (n+1)/n');xlabel('n'); ylabel('b_n');

Series

% Symbolic summationsyms n kS1 = symsum(1/n^2, n, 1, Inf)        % ^ 1/n = /6S2 = symsum(0.5^n, n, 0, Inf)        % ^ 0.5 = 2% Taylor seriessyms xf = exp(x);T5 = taylor(f, x, 'Order', 6)        % 5th order Taylor series for e% Testing for convergence% Ratio testan = 1/factorial(n);ratio = limit(subs(an, n, n+1)/subs(an, n, n), n, Inf)

Example: Find the sum of the alternating harmonic series (-1)/n:

syms nalternating_harmonic = symsum((-1)^(n+1)/n, n, 1, Inf)

This returns ln(2), confirming the mathematical result.

Parameterized Curves

Plotting Parametric Curves

% Parametric equationst = linspace(0, 2*pi, 1000);x = cos(3*t);y = sin(2*t);% Plotfigure;plot(x, y);title('Parametric Curve: x=cos(3t), y=sin(2t)');xlabel('x'); ylabel('y');axis equal; grid on;

Arc Length of Parametric Curves

% Symbolic approachsyms tx = cos(t);y = sin(t);ds = sqrt(diff(x)^2 + diff(y)^2);L = int(ds, t, 0, 2*pi);     % L = 2 for a unit circle

Polar Coordinates and Curves

% Polar plottheta = linspace(0, 2*pi, 1000);r = 2 + cos(5*theta);figure;polarplot(theta, r);title('Polar Curve: r = 2 + cos(5)');% Converting to Cartesian for arc lengthsyms thetar = 2 + cos(5*theta);ds = sqrt(r^2 + diff(r)^2);L = int(ds, theta, 0, 2*pi);

Multivariable Calculus

Functions of Several Variables

% Define symbolic variablessyms x y zf = x^2 + y^2;% Plotting 3D surface[X,Y] = meshgrid(-2:0.1:2, -2:0.1:2);Z = X.^2 + Y.^2;figure;surf(X,Y,Z);title('Surface: z = x + y');xlabel('x'); ylabel('y'); zlabel('z');% Contour plotsfigure;contour(X,Y,Z,20);title('Contour Plot: z = x + y');colorbar;

Partial Derivatives

% Partial derivativesfx = diff(f, x)        f/x = 2xfy = diff(f, y)        f/y = 2y% Second partial derivativesfxx = diff(fx, x)      f/x = 2fxy = diff(fx, y)      f/xy = 0fyy = diff(fy, y)      f/y = 2% Gradientgradient_f = [diff(f,x), diff(f,y)]  % f = (2x, 2y)% Directional derivativedirection = [1, 1];                 % Direction vector uu = direction/norm(direction);      % Unit directiongrad_f = subs([diff(f,x), diff(f,y)], [x,y], [1,1]);D_u_f = dot(grad_f, u)              % Directional derivative at (1,1)

Multiple Integration

% Double integralsf = x*y;I = int(int(f, y, 0, 1), x, 0, 2)    %   x*y dy dx% Triple integralsg = x*y*z;J = int(int(int(g, z, 0, 1), y, 0, 1), x, 0, 1)  %    x*y*z dz dy dx% Changing order of integration depends on the region% Polar coordinates integrationsyms r thetapolar_f = r^2;K = int(int(polar_f*r, r, 0, 1), theta, 0, 2*pi)

Lagrange Multipliers

% Optimization with constraintsyms x y lambdaf = x^2 + y^2;                  % Function to optimizeg = x + y - 1;                   % Constraint g(x,y) = 0% Solve f = g and constrainteq1 = diff(f,x) - lambda*diff(g,x);eq2 = diff(f,y) - lambda*diff(g,y);eq3 = g;solution = solve([eq1, eq2, eq3], [x, y, lambda]);

Vector Calculus

Vector Fields

% Define symbolic vector fieldsyms x y zF = [x^2, y*sin(z), z*exp(x)];% Quiver plot (2D vector field)[X,Y] = meshgrid(-2:0.2:2, -2:0.2:2);U = X.^2;V = Y.*sin(X);    % Using X as z for 3D field visualizationfigure;quiver(X,Y,U,V);title('2D Vector Field');xlabel('x'); ylabel('y');

Line Integrals

% Line integral of a scalar fieldsyms tr = [cos(t), sin(t)];            % Parameterization of curvedr = diff(r, t);f = x^2 + y^2;                   % Scalar fieldintegral_f = int(subs(f, [x,y], r).*norm(dr), t, 0, 2*pi);% Line integral of a vector fieldF = [-y, x];                     % Vector fieldline_int = int(dot(F, dr), t, 0, 2*pi);

Surface Integrals

% Parameterized surfacesyms u vr = [u*cos(v), u*sin(v), u];     % Paraboloid z = x^2 + y^2ru = diff(r, u);rv = diff(r, v);n = cross(ru, rv);norm_n = sqrt(sum(n.^2));% Surface integral of scalar fieldf = x + y + z;surface_int = int(int(subs(f, [x,y,z], r)*norm_n, u, 0, 1), v, 0, 2*pi);

Advanced Topics

Fourier Series

% Computing Fourier series coefficientssyms n x f Lf = piecewise(x=pi, 2*pi-x);L = pi;                          % Half period% Fourier coefficientsa0 = (1/L)*int(f, x, -L, L);an = (1/L)*int(f*cos(n*pi*x/L), x, -L, L);bn = (1/L)*int(f*sin(n*pi*x/L), x, -L, L);% Partial sumsN = 5;partial_sum = a0/2 + symsum(an*cos(n*pi*x/L) + bn*sin(n*pi*x/L), n, 1, N);% Plot original function and Fourier approximationfigure;fplot(f, [-2*L, 2*L]);hold on;fplot(partial_sum, [-2*L, 2*L]);legend('Original Function', sprintf('Fourier Approximation (N=%d)', N));title('Fourier Series Approximation');

Laplace Transforms

% Laplace transformsyms t sf = t^2*exp(-t);F = laplace(f, t, s);           % L{te}(s)% Inverse Laplace transformg = s/(s^2 + 4);G = ilaplace(g, s, t);          % L{s/(s+4)}(t)

Special Functions

MATLAB has built-in support for many special functions encountered in Calculus 2:

% Gamma functionsyms xgamma_val = gamma(sqrt(2));     % (2)% Beta functionbeta_val = beta(2, 3);          % B(2,3)% Error functionerf_val = erf(1);               % erf(1)

Tips for Effective Use of MATLAB in Calculus 2

  1. Verify Analytical Results: Always compare MATLAB's answers with your analytical calculations to build understanding and catch errors.
  2. Precision Settings: For numerical calculations, be aware of precision. Use vpa() for variable-precision arithmetic when needed.
  3. Visualization: Take advantage of MATLAB's plotting capabilities to visualize functions, regions of integration, and vector fields.
  4. Script Files: Save frequently used calculations in script files (.m files) for reuse and documentation.
  5. Live Scripts: Use live scripts for interactive analysis that combines code, output, and formatted text.
  6. Break Down Complex Problems: For complex integrals or transformations, break them into steps and verify each intermediate result.
  7. Symbolic vs. Numerical: Understand when symbolic calculations are necessary and when numerical approximations are more appropriate.
  8. Error Messages: Learn to interpret MATLAB's error messages, as they often point to mathematical issues in your approach.

Tip: When working with symbolic expressions, use simplify(), expand(), or factor() to manipulate expressions into more useful forms. This is particularly helpful when dealing with integrals and derivatives.

Conclusion

MATLAB is a powerful tool for exploration and verification of Calculus 2 concepts. By combining analytical techniques with numerical and symbolic computation, you can gain deeper insight into integration techniques, series, parameterized curves, and multivariable calculus. The examples provided in these notes serve as a starting point for using MATLAB effectively in your Calculus 2 studies.

Remember that while MATLAB can handle complex computations, understanding the underlying mathematics remains essential. Use these computational tools to enhance, not replace, your mathematical reasoning and problem-solving skills.

Reference Files For Matlab Notes For Calculus 2
Screenshoot
File Name
matlab_for_calculus2.pdf

File Size
0.26 MB

File Type
PDF

File Site
Description
This file is just a reference file for Matlab Notes For Calculus 2. Does not guarantee that the specific things you want are included in it.
Direct download (wait 10 seconds)

Matlab Notes For Calculus 2 and Reference File Download Link


admin
Admin
2026-06-08 05:40:21

MATLAB Cheat Sheet For Calculus and Reference File Download Link


admin
Admin
2026-06-09 05:32:15

Tutorial Menggunakan Software MATLAB Dalam Menentukan Fungsi Distribusi Probabilitas dan L...


admin
Admin
2026-05-27 10:30:14

Numerical Optimization Using MATLAB and Reference File Download Link


admin
Admin
2026-06-06 23:46:17

**Sudoku Solving Strategies Using MATLAB** and Reference File Download Link


admin
Admin
2026-06-09 02:56:20