JnU B.Sc. in CSE — 3rd Year 1st Semester, Mid Term 2 (14th Batch, Solved)
Created ৯ আগ, ২০২৬
Three questions, worth 4, 3, and 4 marks — gradient descent optimization, recovering a function from its derivative, and constrained optimization with Lagrange multipliers.
Question 1 — Gradient Descent Optimization
Suppose we apply gradient descent to minimize
f(x,y)=x2+4y2+2xy−4x+6
with learning rate α=0.1 and current parameter value (x0,y0)=(2,−1).
Derive the general gradient descent update equation for x and y.
Perform one iteration to compute (x1,y1).
Compute f(x0,y0) and f(x1,y1).
State whether the update improved the objective.
Concept Needed
Gradient descent moves each parameter a small step opposite to the partial derivative of the objective at the current point — that direction is the one along which f decreases fastest.
Gradient descent update rule
xn+1=xn−α∂x∂f,yn+1=yn−α∂y∂f
Given / Required
Given f(x,y)=x2+4y2+2xy−4x+6, α=0.1, (x0,y0)=(2,−1). Required: the update rule, (x1,y1), f(x0,y0), f(x1,y1), and whether the step improved the objective.
Step 1: Find the Partial Derivatives
∂x∂f=2x+2y−4,∂y∂f=8y+2x
Step 2: Write the Update Equations
xn+1=xn−α(2xn+2yn−4)
yn+1=yn−α(8yn+2xn)
Step 3: Evaluate the Gradient at (2,−1)
∂x∂f(2,−1)=2(2)+2(−1)−4=4−2−4=−2
∂y∂f(2,−1)=8(−1)+2(2)=−8+4=−4
Step 4: Apply the Update Rule with α=0.1
x1=2−0.1(−2)=2+0.2=2.2
y1=−1−0.1(−4)=−1+0.4=−0.6
So (x1,y1)=(2.2,−0.6).
Step 5: Compute f(x0,y0) and f(x1,y1)
At (x0,y0)=(2,−1):
f(2,−1)=(2)2+4(−1)2+2(2)(−1)−4(2)+6=4+4−4−8+6=2
At (x1,y1)=(2.2,−0.6):
f(2.2,−0.6)=(2.2)2+4(−0.6)2+2(2.2)(−0.6)−4(2.2)+6
=4.84+1.44−2.64−8.8+6=0.84
Step 6: Did the Update Improve the Objective?
Since f(x1,y1)=0.84<f(x0,y0)=2, the function value decreased.
Verification
Since the gradient direction (−2,−4) points where f decreases, and we moved opposite to it, a lower f value is expected. This matches the computed answer, so the calculation is verified.
Final Answer
Update rule: xn+1=xn−α(2xn+2yn−4), yn+1=yn−α(8yn+2xn). One step gives (x1,y1)=(2.2,−0.6); f decreased from 2 to 0.84, so the update improved the objective.
Exam Tip
Always calculate the gradient first at the given point, then apply the update formula. A decreasing f value confirms gradient descent is moving toward the minimum.
Common Mistake
Forgetting the negative sign in the update rule. Also, using the old x0 value instead of the updated x1 while computing the y1 update — both partial derivatives at step n must use (xn,yn) simultaneously, not a mix of old and new values.
Quick Revision Point
Gradient descent always moves in the negative gradient direction, since −∇f points toward locally decreasing f.
Question 2 — Finding a Function from its Derivative
If
limh→0hf(x+h)−f(x)=3x2−4x+1andf(1)=5,
find f(x). Hence determine the coordinates where the tangent is horizontal.
Concept Needed
The given limit is exactly the definition of f′(x), so f′(x)=3x2−4x+1. Recovering f(x) from f′(x) means integrating, and the constant of integration is pinned down using the given point f(1)=5. A horizontal tangent occurs wherever the slope f′(x) is zero.
Given / Required
Given f′(x)=3x2−4x+1 and f(1)=5. Required: f(x), and the point(s) where the tangent line is horizontal.
Step 1: Integrate f′(x) to get f(x)
f(x)=∫(3x2−4x+1)dx=x3−2x2+x+C
Step 2: Use f(1)=5 to Find C
f(1)=(1)3−2(1)2+(1)+C=1−2+1+C=0+C
5=C⇒C=5
Recovered function
f(x)=x3−2x2+x+5
Step 3: Find Where the Tangent is Horizontal
A horizontal tangent means slope =0, i.e. f′(x)=0:
3x2−4x+1=0
Factoring:
3x2−3x−x+1=0
3x(x−1)−1(x−1)=0
(3x−1)(x−1)=0
x=31orx=1
Step 4: Find the Corresponding y-coordinates
At x=1:
f(1)=1−2+1+5=5
At x=31:
f(31)=(31)3−2(31)2+31+5=271−92+31+5
Converting to a common denominator of 27:
=271−276+279+27135=27139
Verification
Differentiating f(x)=x3−2x2+x+5 gives back 3x2−4x+1, which matches the given derivative — so the recovered function is correct.
Final Answer
f(x)=x3−2x2+x+5
Horizontal tangents at (1,5) and (31,27139).
Exam Tip
Always integrate term by term and don't forget the "+C" — the given point is the only way to pin it down, so don't skip that step.
Common Mistake
Forgetting the constant of integration C. Sign errors while factoring 3x2−4x+1. Forgetting to compute the y-coordinate after finding each x value.
Quick Revision Point
"Horizontal tangent means slope is zero" — always set f′(x)=0 to locate such points, then plug each root back into f(x) (not f′(x)) for the y-coordinate.
Question 3 — Constrained Optimization using Lagrange Multipliers
Minimize
f(x,y)=2x2+3y2+xysubject tox+3y=9
Form the Lagrangian.
Compute the three first-order conditions.
Solve for (x∗,y∗).
Find the minimum value of f(x,y).
Concept Needed
Lagrange multipliers convert a constrained optimization problem into an unconstrained one by introducing a multiplier λ for the constraint. At the optimum, ∇f=λ∇g — the gradients of the objective and constraint are parallel.
Lagrangian construction
L(x,y,λ)=f(x,y)−λ(g(x,y)−k)
Given / Required
Given f(x,y)=2x2+3y2+xy, constraint g(x,y):x+3y=9. Required: (x∗,y∗) and the minimum value of f.
Step 1: Form the Lagrangian
L(x,y,λ)=2x2+3y2+xy−λ(x+3y−9)
Step 2: Write the First-Order Conditions
Setting all three partial derivatives to zero:
∂x∂L=0:4x+y−λ=0⋯(1)
∂y∂L=0:6y+x−3λ=0⋯(2)
∂λ∂L=0:x+3y−9=0⋯(3)
Step 3: Eliminate λ
From (1): λ=4x+y. Substitute into (2):
6y+x−3(4x+y)=0
6y+x−12x−3y=0
3y−11x=0⇒y=311x⋯(4)
Step 4: Substitute into the Constraint
x+3(311x)=9
x+11x=9
12x=9⇒x∗=43
Step 5: Find y∗
y∗=311(43)=411
So (x∗,y∗)=(43,411).
Verification of the Constraint
x∗+3y∗=43+433=436=9✓
Step 6: Compute the Minimum Value of f(x,y)
f(43,411)=2(43)2+3(411)2+(43)(411)
2(169)=1618,3(16121)=16363,43⋅411=1633
f=1618+16363+1633=16414=8207
Final Answer
(x∗,y∗)=(43,411),fmin=8207=25.875
Since f(x,y) is a positive-definite quadratic form (coefficients 2,3 positive and no dominating negative cross-term), the constrained stationary point found here is indeed a minimum.
Exam Tip
Form L=f−λ(g−k) carefully with the correct sign, then always verify your solution satisfies the original constraint before reporting the final answer.
Common Mistake
Sign error while forming L=f−λ(g−9). Algebra mistakes while eliminating λ between the two first-order conditions. Forgetting to check that the solution satisfies the original constraint.
Quick Revision Point
"Same slope direction" — at the optimum, the gradient of f is parallel to the gradient of the constraint: ∇f=λ∇g.