...

/

Solutions to Basic Optimization Problems

Solutions to Basic Optimization Problems

Learn how to solve the optimization problems of the previous lesson.

Exercise 1

We had to solve four optimization problems already written in mathematical form. Remember that writing an optimization problem in mathematical form can be very difficult. But we’re warming up, so let's simplify things a little bit.

Problem 1

minxx4\min_x x^4

The first problem is to find the minimum of x4x^4. This function is very similar to x2x^2 since they both are always greater than or equal to zero. Any number powered by an even exponent will be positive. But also, they’re equal to zero when x=0x = 0. If the function can never be less than zero but we know a point when it’s equal to zero, then that point should be the minimum of the function! So the answer is x=0x = 0.

Problem 2

minxx4+6x2+1\min_x x^4 + 6x^2 + 1

The second exercise is a little trickier. Now the function is more complex: x4+6x2+1x^4 + 6x^2 + 1. But don’t be afraid! Let’s plot this new function.

Press + to interact
import matplotlib.pyplot as plt
def f(x):
return x**4 + 6*x**2 + 1
inputs = list(range(-10, 11))
outputs = list(map(f, inputs))
plt.plot(inputs, outputs, '.')
# !!!: This line is used here for technical purposes regarding Educative environment
# you will use 'plt.show()' in your computer instead
plt.savefig("output/image.png") # plt.show()

As we can see, this function is still very similar to x2x^2. The minimum of the function is x=0x = 0 again. The only difference is that the value of the function at that point is one, not zero. So the changes concerning the previous code are:

  • Line 4: We change the function
...