Solutions to Basic Optimization Problems
Learn how to solve the optimization problems of the previous lesson.
We'll cover the following...
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
The first problem is to find the minimum of . This function is very similar to 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 . 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 .
Problem 2
The second exercise is a little trickier. Now the function is more complex: . But don’t be afraid! Let’s plot this new function.
import matplotlib.pyplot as pltdef f(x):return x**4 + 6*x**2 + 1inputs = 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 insteadplt.savefig("output/image.png") # plt.show()
As we can see, this function is still very similar to . The minimum of the function is 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