0% found this document useful (0 votes)
2 views10 pages

MATLAB Solutions for Differential Equations

The document contains solutions to various mathematical problems involving symbolic computation, calculus, and differential equations. It includes the use of MATLAB for plotting functions, finding minima, and solving ordinary differential equations with given initial conditions. Each solution is presented with relevant equations, computations, and results.

Uploaded by

andrew Mhaka
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)
2 views10 pages

MATLAB Solutions for Differential Equations

The document contains solutions to various mathematical problems involving symbolic computation, calculus, and differential equations. It includes the use of MATLAB for plotting functions, finding minima, and solving ordinary differential equations with given initial conditions. Each solution is presented with relevant equations, computations, and results.

Uploaded by

andrew Mhaka
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

HIT 1202

ASSIGNMENT 2
KASU H240091X HECP

KAGURA H240163J HECP

BWONI-MACHAWIRA H240437P HECP

Solution 1a
syms x y
lhs1 = sin(4*x)

lhs1 =

rhs1 = 4*sin(x)*cos(x) - 8*sin(x)^3*cos(x)

rhs1 =

simplify(lhs1 - rhs1)

ans =

Solution 1b
syms x y;
lhs2 = cos(x)*cos(y)

lhs2 =

rhs2 = (1/2) * (cos(x - y) + cos(x + y))

rhs2 =

simplify(lhs2 - rhs2)

ans =

Solution 2
syms x
f5=x^3-12*x^2+40.25*x-36.5

f5 =

1
fplot(f5,[0,8])

[x1 fval1]=fminbnd('x^3-12*x^2+40.25*x-36.5',5,7)

x1 =
5.6073
fval1 =
-11.8043

Solution 3
[x2 fval2]=fminbnd('-x^3+12*x^2-40.25*x+36.5',1,3)

x2 =
2.3927
fval2 =
-4.8043

Solution 4a
k = 0.25;
u = linspace(0,1,100);
pi = (k * u .* (1 - u)) ./ (k + u)

pi = 1×100

2
0 0.0096 0.0183 0.0262 0.0334 0.0399 0.0458 0.0512

figure

plot(u, pi, 'b', 'LineWidth', 2)


xlabel('u')
ylabel('p')
title('Power Output vs. Velocity')

grid on

Solution 4b
[max_p, idx] = max(pi)

max_p =
0.0955
idx =
32

max_u = u(idx)

max_u =
0.3131

disp([' u = ', num2str(max_u)])

3
u = 0.31313

Solution 4c
disp(['Max Power: ', num2str(max_p),])

Max Power: 0.095484

Solution 5a
syms v m k T f5 pi
E1 =f5==sqrt(2/pi* (m/(k*T))^(3)) * v^2 * exp(-m*v^2/(2*k*T))

E1 =

Solution 5b
d1 = diff(E1,v)

d1 =

Solution 5c
vp = solve(d1, v)

vp =

vp_expected = sqrt(2*k*T/m)

vp_expected =

simplify(vp - vp_expected)

ans =

4
Solution 6a
syms x y z
f6 =1 + x*y^2-64*z^2

f6 =

f_x= diff(f6,x)

f_x =

f_y= diff(f6,y)

f_y =

f_z= diff(f6,z)

f_z =

f_xz=diff(f_x,z)

f_xz =

f_zx=diff(f_z,x)

f_zx =

Solution 6b
f2 = 70*x - sqrt(y^2 + z^2)

f2 =

fx2 = diff(f2, x)

fx2 =

fy2 = diff(f2, y)

fy2 =

5
fz2 = diff(f2, z)

fz2 =

fxx2 = diff(fx2, x)

fxx2 =

fzz2 = diff(fz2, z)

fzz2 =

Solution 6c
f5 = 22*y*z* log(x*y)

f5 =

fx5 = diff(f5, x)

fx5 =

fy5 = diff(f5, y)

fy5 =

fz5 = diff(f5, z)

fz5 =

fxx5 = diff(fx5, x)

fxx5 =

fzz5 = diff(fz5, z)

fzz5 =

Solution 6d
f6 = 64*exp(-x*y*z)

f6 =

6
fx6 = diff(f6, x)

fx6 =

fy6 = diff(f6, y)

fy6 =

fz6 = diff(f6, z)

fz6 =

fxx6 = diff(fx6, x)

fxx6 =

fzz6 = diff(fz6, z)

fzz6 =

Solution 7a
integral1 = int(((22 + 1) * x^3) / sqrt(1 - x^2), x)

integral1 =

Solution 7b
integral2 = int(x^2 * cos(x), x)

integral2 =

Solution 8
syms y(x)
ode = diff(y, x, 2) + diff(y, x) - 2*y == 0

ode(x) =

cond1 = y(0) == 9

cond1 =

cond2 = diff(y, x) == 70

cond2(x) =

7
cond3 = subs(cond2, x, 0)

cond3(x) =

solution = dsolve(ode, cond1, cond3)

solution =

disp(solution)

Solution 9
syms y(x)
ode = diff(y, x, 2) + 9*y == cos(3*x) + sin(3*x)

ode(x) =

sol = dsolve(ode)

sol =

disp(sol)

Solution 10
syms i(t) L R C

ode = L * diff(i, t, 2) + R * diff(i, t) + (1/C) * i == 0

ode(t) =

8
cond1 = i(0) == 0

cond1 =

cond2 = diff(i, t) == 8

cond2(t) =

cond3 = subs(cond2, t, 0)

cond3(t) =

solution = dsolve(ode, cond1, cond3)

solution =

disp(solution)

Solution 11
syms x(t) y(t) z(t)
c1 = 1

9
c1 =
1

c2 = 2

c2 =
2

eq1 = diff(x, t) == -c1*x

eq1(t) =

eq2 = diff(y, t) == c1*x - c2*y

eq2(t) =

eq3 = diff(z, t) == c2*y

eq3(t) =

sol = dsolve([eq1, eq2, eq3], x(0) == 5, y(0) == 0, z(0) == 0);

disp(sol)

y: 5*exp(-t) - 5*exp(-2*t)
x: 5*exp(-t)
z: 5*exp(-2*t) - 10*exp(-t) + 5

10

You might also like