0% found this document useful (0 votes)
10 views

tutorial8

Uploaded by

jayakailas34
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)
10 views

tutorial8

Uploaded by

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

% TUTORIAL 8

% Question 1
% Define system variables
syms x y
% Define the function
f1 = (x^3) * (y^2) * (12-x-y)

f1 =

% First-order partial derivatives


disp('First-order partiral derivatives: ')

First-order partiral derivatives:

p = diff(f1, x)

p =

q = diff(f1, y)

q =

% Second-order partial derivatives


disp('Second-order partial derivatives: ')

Second-order partial derivatives:

r = diff(p, x)

r =

s = diff(p, y)

s =

t = diff(q, y)

t =

% Solve for critical points


[critical_point_x, critical_point_y] = solve([p == 0, q == 0], [x, y]);
critical_points = [critical_point_x, critical_point_y]

critical_points =

1
for i = 1:length(critical_point_x)
% Current critical point
current_points = [critical_point_x(i), critical_point_y(i)]

% Evaluate second-order derivatives at the critical point


r1 = subs(r, {x, y}, current_points)
s1 = subs(s, {x, y}, current_points)
t1 = subs(t, {x, y}, current_points)

% Hessian determinant
disp('h = r*t - (s^2)')
h1 = r1 * t1 - (s1^2)

% Classification of critical point


if (h1 > 0 && r1 > 0)
disp('The function has a local minimum at this point.');
elseif (h1 > 0 && r1 < 0)
disp('The function has a local maximum at this point.');
elseif (h1 < 0)
disp('The function has a saddle point at this point.');
else
disp('The second derivative test is inconclusive. (Test Fails)');
end
end

current_points =
r1 =
s1 =
t1 =
h = r*t - (s^2)
h1 =
The function has a local maximum at this point.
current_points =
r1 =
s1 =
t1 =
h = r*t - (s^2)
h1 =
The second derivative test is inconclusive. (Test Fails)

% Question 2
% Define system variables
syms x y
% Define the function
f2 = (x^2)+(y^2)-6*x+12

f2 =

2
% First-order partial derivatives
disp('First-order partiral derivatives: ')

First-order partiral derivatives:

p = diff(f2, x)

p =

q = diff(f2, y)

q =

% Second-order partial derivatives


disp('Second-order partial derivatives: ')

Second-order partial derivatives:

r = diff(p, x)

r =

s = diff(p, y)

s =

t = diff(q, y)

t =

% Solve for critical points


[critical_point_x, critical_point_y] = solve([p == 0, q == 0], [x, y]);
critical_points = [critical_point_x, critical_point_y]

critical_points =

for i = 1:length(critical_point_x)
% Current critical point
current_points = [critical_point_x(i), critical_point_y(i)]

% Evaluate second-order derivatives at the critical point


r2 = subs(r, {x, y}, current_points)
s2 = subs(s, {x, y}, current_points)
t2 = subs(t, {x, y}, current_points)

% Hessian determinant
disp('h = r*t - s^2')
h2 = r2 * t2 - (s2^2)

3
% Classification of critical point
if (h2 > 0 && r2 > 0)
disp('The function has a local minimum at this point.');
elseif (h2 > 0 && r2 < 0)
disp('The function has a local maximum at this point.');
elseif (h2 < 0)
disp('The function has a saddle point at this point.');
else
disp('The second derivative test is inconclusive. (Test Fails)');
end
end

current_points =
r2 =
s2 =
t2 =
h = r*t - s^2
h2 =
The function has a local minimum at this point.

% Question 3
% Define system variables
syms x y
% Define the function
f3 = (x^2)+(y^2)-x*y-2*x-y

f3 =

% First-order partial derivatives


disp('First-order partiral derivatives: ')

First-order partiral derivatives:

p = diff(f3, x)

p =

q = diff(f3, y)

q =

% Second-order partial derivatives


disp('Second-order partial derivatives: ')

Second-order partial derivatives:

r = diff(p, x)

4
r =

s = diff(p, y)

s =

t = diff(q, y)

t =

% Solve for critical points


[critical_point_x, critical_point_y] = solve([p == 0, q == 0], [x, y]);
critical_points = [critical_point_x, critical_point_y]

critical_points =

for i = 1:length(critical_point_x)
% Current critical point
current_points = [critical_point_x(i), critical_point_y(i)]

% Evaluate second-order derivatives at the critical point


r3 = subs(r, {x, y}, current_points)
s3 = subs(s, {x, y}, current_points)
t3 = subs(t, {x, y}, current_points)

% Hessian determinant
disp('h = r*t - s^2')
h3 = r3 * t3 - (s3^2)

% Classification of critical point


if (h3 > 0 && r3 > 0)
disp('The function has a local minimum at this point.');
elseif (h3 > 0 && r3 < 0)
disp('The function has a local maximum at this point.');
elseif (h3 < 0)
disp('The function has a saddle point at this point.');
else
disp('The second derivative test is inconclusive. (Test Fails)');
end
end

current_points =

r3 =
s3 =

5
t3 =
h = r*t - s^2
h3 =
The function has a local minimum at this point.

% Question 4
% Define system variables
syms x y
% Define the function
f4 = (x^2) * (y^3) * (1-x-y)

f4 =

% First-order partial derivatives


disp('First-order partiral derivatives: ')

First-order partiral derivatives:

p = diff(f4, x)

p =

q = diff(f4, y)

q =

% Second-order partial derivatives


disp('Second-order partial derivatives: ')

Second-order partial derivatives:

r = diff(p, x)

r =

s = diff(p, y)

s =

t = diff(q, y)

t =

% Solve for critical points


[critical_point_x, critical_point_y] = solve([p == 0, q == 0], [x, y]);
critical_points = [critical_point_x, critical_point_y]

6
critical_points =

for i = 1:length(critical_point_x)
% Current critical point
current_points = [critical_point_x(i), critical_point_y(i)]

% Evaluate second-order derivatives at the critical point


r4 = subs(r, {x, y}, current_points)
s4 = subs(s, {x, y}, current_points)
t4 = subs(t, {x, y}, current_points)

% Hessian determinant
disp('h = r*t - s^2')
h4 = r4 * t4 - (s4^2)

% Classification of critical point


if (h4 > 0 && r4 > 0)
disp('The function has a local minimum at this point.');
elseif (h4 > 0 && r4 < 0)
disp('The function has a local maximum at this point.');
elseif (h4 < 0)
disp('The function has a saddle point at this point.');
else
disp('The second derivative test is inconclusive. (Test Fails)');
end
end

current_points =

r4 =

s4 =

t4 =

h = r*t - s^2
h4 =

The function has a local maximum at this point.

7
current_points =
r4 =
s4 =
t4 =
h = r*t - s^2
h4 =
The second derivative test is inconclusive. (Test Fails)

% Question 5
% Define system variables
syms x y
% Define the function
f5 = (x^3)+x*(y^2)-12*(x^2)+21*x-2*(y^2)

f5 =

% First-order partial derivatives


disp('First-order partiral derivatives: ')

First-order partiral derivatives:

p = diff(f5, x)

p =

q = diff(f5, y)

q =

% Second-order partial derivatives


disp('Second-order partial derivatives: ')

Second-order partial derivatives:

r = diff(p, x)

r =

s = diff(p, y)

s =

t = diff(q, y)

t =

% Solve for critical points

8
[critical_point_x, critical_point_y] = solve([p == 0, q == 0], [x, y]);
critical_points = [critical_point_x, critical_point_y]

critical_points =

for i = 1:length(critical_point_x)
% Current critical point
current_points = [critical_point_x(i), critical_point_y(i)]

% Evaluate second-order derivatives at the critical point


r5 = subs(r, {x, y}, current_points)
s5 = subs(s, {x, y}, current_points)
t5 = subs(t, {x, y}, current_points)

% Hessian determinant
disp('h = r*t - s^2')
h5 = r5 * t5 - (s5^2)

% Classification of critical point


if (h5 > 0 && r5 > 0)
disp('The function has a local minimum at this point.');
elseif (h5 > 0 && r5 < 0)
disp('The function has a local maximum at this point.');
elseif (h5 < 0)
disp('The function has a saddle point at this point.');
else
disp('The second derivative test is inconclusive. (Test Fails)');
end
end

current_points =
r5 =
s5 =
t5 =
h = r*t - s^2
h5 =
The function has a local maximum at this point.
current_points =
r5 =
s5 =
t5 =
h = r*t - s^2
h5 =
The function has a local minimum at this point.

9
current_points =
r5 =

s5 =
t5 =
h = r*t - s^2
h5 =
The function has a saddle point at this point.
current_points =
r5 =

s5 =
t5 =
h = r*t - s^2
h5 =
The function has a saddle point at this point.

10

You might also like