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

GET210 Octave Lab Manual Complete

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)
59 views8 pages

GET210 Octave Lab Manual Complete

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
You are on page 1/ 8

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

You might also like