0% found this document useful (0 votes)
51 views8 pages

Octave Lab Manual for Engineering Math

The GET 210: Octave Lab Manual provides a comprehensive guide on computational concepts in Engineering Mathematics II using GNU Octave, featuring lab problems and exercises on topics such as basic syntax, differentiation, integration, ordinary differential equations, and complex analysis. Each section includes example code and explanations for solving various mathematical problems. The manual also contains take-home exercises to reinforce learning.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views8 pages

Octave Lab Manual for Engineering Math

The GET 210: Octave Lab Manual provides a comprehensive guide on computational concepts in Engineering Mathematics II using GNU Octave, featuring lab problems and exercises on topics such as basic syntax, differentiation, integration, ordinary differential equations, and complex analysis. Each section includes example code and explanations for solving various mathematical problems. The manual also contains take-home exercises to reinforce learning.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

GET 210: Octave Lab Manual

This lab manual covers key computational concepts in Engineering


Mathematics II using GNU Octave. Each topic includes two lab problems with
solutions and one take-home exercise.
Basic Syntax and Commands
Math Operations

a = 5;

b = 3;

c = a + b;

disp(c); % Displays 8

Vectors and Matrices

v = [1, 2, 3]; % Row vector

M = [1 2; 3 4]; % 2x2 Matrix

M_transpose = M'; % Transpose

Element-wise Operations

v = [1, 2, 3];

v_squared = v .^ 2; % [1, 4, 9]

Plotting Functions
Basic Plot

x = 0:0.1:2*pi;

y = sin(x);

plot(x, y);

xlabel('x'); ylabel('sin(x)');

title('Plot of sin(x)');
3D Plot

[x, y] = meshgrid(-2:0.1:2, -2:0.1:2);

z = x.^2 + y.^2;

surf(x, y, z);

1. Differentiation and Integration


Lab Problem 1: Differentiate f (x)=x3 +2 x 2 + x and evaluate at x=2.

Code:

pkg load symbolic;


syms x;
f = x^3 + 2*x^2 + x;
df = diff(f, x);
val = subs(df, x, 2);
disp(val);

Explanation:

Computes the derivative of f (x) and evaluates it at x=2.

Lab Problem 2: Integrate f (x)=sin(x )exp (x) symbolically.

Code:

f = sin(x)*exp(x);
intf = int(f, x);
disp(intf);

Explanation:

Performs symbolic integration of a product function.

Take-Home Exercise:
Exercise: Differentiate and integrate f (x)=ln(x 2 +1) .

2. Ordinary Differential Equations


dy
Lab Problem 1: Solve =x− y with y (0)=1 using ode 45.
dx

Code:

graphics_toolkit gnuplot

function dydx = f(x, y)


dydx = x - y;
end

[x, y] = ode45(@f, [0 5], 1);


plot(x, y);

Explanation:

Numerically solves a first-order ODE.

dy
Lab Problem 2: Solve =−2 y+ cos(x ), y (0)=0.
dx

Code:

function dydx = f(x, y)


dydx = -2*y + cos(x);
end

[x, y] = ode45(@f, [0 5], 0);


plot(x, y);

Explanation:

Solves a nonhomogeneous linear ODE.

Take-Home Exercise:

dy
Exercise: Solve =sin( x )− y , y (0)=2.
dx
3. Calculus: Vector and Vector-Valued Functions, Line and Multiple
Integrals
Lab Problem 1: Compute the velocity and acceleration of r (t )=[cos (t), sin(t ), t ].

Code:

pkg load symbolic;


syms t;
r = [cos(t), sin(t), t];
v = diff(r, t);
a = diff(v, t);
disp('Velocity:'), disp(v);
disp('Acceleration:'), disp(a);

Explanation:

Finds velocity and acceleration from a vector-valued function.

Lab Problem 2: Evaluate the double integral ∫ ∫ ( x 2 + y 2) dx dy over [0 ,1] x [0 , 1].

Code:

syms x y;
f = x^2 + y^2;
I = int(int(f, x, 0, 1), y, 0, 1);
disp('Double Integral:'), disp(I);

Explanation:

Symbolic evaluation of a double integral over a square region.

Take-Home Exercise:

Exercise: Evaluate the line integral ∮(x dy− y dx ) over the unit circle.
4. Second-Order Differential Equations
Lab Problem 1: Solve y ' '−3 y '+ 2 y =0 with y (0)=1, y '(0)=0.

Code:

pkg load symbolic;


syms y(x);
Dy = diff(y, x);
ode = diff(y, x, 2) - 3*Dy + 2*y == 0;
conds = [y(0)==1, Dy(0)==0];
sol = dsolve(ode, conds);
disp('Solution:'), disp(sol);

Explanation:

Solves a second-order linear homogeneous differential equation.

Lab Problem 2: Solve y ' '+ y =sin(x ) using symbolic computation.

Code:

ode = diff(y, x, 2) + y == sin(x);


sol = dsolve(ode);
disp('General Solution:'), disp(sol);

Explanation:

Solves a second-order nonhomogeneous differential equation.

Take-Home Exercise:

Exercise: Solve y ' ' + 4 y=0 with y (0)=0 and y '(0)=1.

5. Elementary Complex Analysis and Special Functions


Lab Problem 1: Evaluate f ( z)=z2 +1for z=2+3 i .

Code:
z = 2 + 3i;
f = z^2 + 1;
disp('f(z) ='), disp(f);

Explanation:

Evaluates a complex function for a given complex input.

1
Lab Problem 2: Plot the magnitude of f (z)= over the complex grid.
z

Code:

[x, y] = meshgrid(-2:0.1:2, -2:0.1:2);


z = x + 1i*y;
f = 1 ./ z;
surf(x, y, abs(f)); title('|1/z|');

Explanation:

Visualizes the magnitude of a complex function.

Take-Home Exercise:

Exercise: Evaluate and plot f (z)=e z for z=x +iy .

6. Cauchy-Riemann Equations, Harmonic Functions, and Conformal


Mapping
Lab Problem 1: Verify Cauchy-Riemann equations for u=x2 − y 2 , v=2 xy .

Code:

syms x y;
u = x^2 - y^2; v = 2*x*y;
CR1 = diff(u, x) == diff(v, y);
CR2 = diff(u, y) == -diff(v, x);
disp('CR1:'), disp(CR1);
disp('CR2:'), disp(CR2);
Explanation:

Checks the analyticity of a complex function using the Cauchy-Riemann equations.

Lab Problem 2: Map the unit circle under f (z)=z2 .

Code:

theta = linspace(0, 2*pi, 100);


z = exp(1i*theta);
w = z.^2;
plot(real(w), imag(w)); axis equal;
title('Conformal Map: z^2');

Explanation:

Plots the image of the unit circle under a conformal map.

Take-Home Exercise:

Exercise: Check whether u( x , y)=x2 + y 2 is harmonic, and plot the image of the unit circle
1
under f (z)= .
z

Common questions

Powered by AI

Mapping the unit circle under \( f(z) = z^2 \) illustrates conformal mapping principles by transforming every point on the circle to a new location, preserving angles but not distances. The transformation doubles the angle at the origin of each radius in the circle, thus illustrating how conformal mappings locally preserve angles but might distort shapes. This concept is fundamental in complex analysis, particularly in applications like aerodynamics and electromagnetic theory, where mappings simplify complex shapes into analyzable forms .

Element-wise operations on vectors in Octave, such as \( v .^ 2 \) for vector \( v = [1, 2, 3] \), are crucial for data manipulation that treats each element individually. This type of operation allows applying functions concurrently across vector elements without explicit loops, facilitating efficient computation. Such operations are significant in applications like signal processing where element-wise transformations can enhance filtering and analysis of data .

Evaluating the double integral \( \iint (x^2 + y^2) \, dA \) over a region like \([0,1] \times [0,1]\) provides insights into the behavior of functions across two dimensions. It involves integrating first one variable and then the other, offering a way to compute volumes under surfaces. This understanding aids in appreciating concepts such as surface area, volume, and the accumulation of quantities over areas, laying groundwork for applications in physics and engineering where multivariable processes are involved .

Elementary complex functions and their evaluations help understand complex numbers' behavior in complex analysis. For example, evaluating \( f(z) = z^2 + 1 \) at \( z = 2 + 3i \) involves computing \( (2 + 3i)^2 + 1 \), resulting in \( -5 + 12i \). This process highlights the complex function's nature, extending real number computations to complex planes. Such evaluations form the basis for more advanced theories and applications in fields like electrical engineering and fluid dynamics .

Verifying the Cauchy-Riemann equations for a function is crucial as it determines the function's analyticity. If a complex function \( f(z) = u(x, y) + iv(x, y) \) satisfies the Cauchy-Riemann equations, \( \frac{\partial u}{\partial x} = \frac{\partial v}{\partial y} \) and \( \frac{\partial u}{\partial y} = -\frac{\partial v}{\partial x} \), then the function is analytic at that point. Analyticity signifies that the function is differentiable in the complex plane, which is vital for complex analysis and conformal mapping applications .

To plot a function in Octave, you typically define the range of your independent variable, compute the dependent variable's values, and use the plot function to visualize it. For example, plotting \( \sin(x) \) involves defining \( x = 0:0.1:2\pi \), computing \( y = \sin(x) \), and then using \( plot(x, y) \) to visualize the sine function. This process helps in understanding the behavior and properties of mathematical functions visually .

Symbolic differentiation and integration in Octave allow for exact solutions of derivatives and integrals, facilitating a deeper understanding of calculus concepts. For instance, differentiating and integrating \( f(x) = x^3 + 2x^2 + x \) showcases how functions change rate (differentiation) and accumulate (integration) at computed values. This exactness aids in visualizing and solving complex engineering problems analytically rather than numerically, making it highly beneficial for engineering mathematics .

Solving nonhomogeneous differential equations like \( y'' + y = \sin(x) \) symbolically facilitates understanding the interaction between the differential equation's homogeneous and particular solutions. Typically, the general solution is the sum of a homogeneous solution and a particular solution fitting the nonhomogeneous term. This symbolic approach aids in characterizing system dynamics where external influences (e.g., forcing terms like \( \sin(x) \)) are modeled, crucial in physics and engineering problem-solving .

When solving ordinary differential equations (ODEs) using ode45 in Octave, the initial condition is specified as part of the function call. For instance, in solving \( \frac{dy}{dx} = x - y \) with the initial condition \( y(0) = 1 \), the command \( [x, y] = ode45(@f, [0 5], 1) \) includes '1' as the initial condition for \( y \). Incorporating initial conditions is crucial as it determines the specific solution to the ODE representing the state of the system at the starting point .

Confirming harmonicity in functions such as \( u(x, y) = x^2 + y^2 \) is essential as it demonstrates the solution's satisfaction of Laplace's equation (\( \Delta u = 0 \)). Harmonic functions are significant in complex analysis and potential theory, often modeling steady-state heat distributions and electrostatics. Identifying a function as harmonic indicates conformal mappings' preservation of angles and the potential function's stability, which are critical properties in mathematical physics .

You might also like