<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 In this tutorial we examine the effect of changing the target(s) on the results of a horsetail matching optimization. 
We'll use TP3 from the demo problems. We also define a function for easy plotting using matplotlib.
Step1:  In the following code we setup a horsetail matching optimization using test problem 3, and then run optimizations under three targets
<ASSISTANT_TASK:>
Python Code:
from horsetailmatching import HorsetailMatching, GaussianParameter
from horsetailmatching.demoproblems import TP3
from scipy.optimize import minimize
import numpy as np
import matplotlib.pyplot as plt
def plotHorsetail(theHM, c='b', label=''):
    (q, h, t), _, _ = theHM.getHorsetail()
    plt.plot(q, h, c=c, label=label)
    plt.plot(t, h, c=c, linestyle='dashed')
    plt.xlim([-10, 10])
Explanation: In this tutorial we examine the effect of changing the target(s) on the results of a horsetail matching optimization. 
We'll use TP3 from the demo problems. We also define a function for easy plotting using matplotlib.
End of explanation
u1 = GaussianParameter()
def standardTarget(h):
    return 0.
theHM = HorsetailMatching(TP3, u1, ftarget=standardTarget, samples_prob=5000)
solution1 = minimize(theHM.evalMetric, x0=0.6, method='COBYLA',
        constraints=[{'type': 'ineq', 'fun': lambda x: x}, {'type': 'ineq', 'fun': lambda x: 1-x}])
theHM.evalMetric(solution1.x)
print(solution1)
plotHorsetail(theHM, c='b', label='Standard')
def riskAverseTarget(h):
    return 0. - 3.*h**3.
theHM.ftarget=riskAverseTarget
solution2 = minimize(theHM.evalMetric, x0=0.6, method='COBYLA',
        constraints=[{'type': 'ineq', 'fun': lambda x: x}, {'type': 'ineq', 'fun': lambda x: 1-x}])
theHM.evalMetric(solution2.x)
print(solution2)
plotHorsetail(theHM, c='g', label='Risk Averse')
def veryRiskAverseTarget(h):
    return 1. - 10.**h**10.
theHM.ftarget=veryRiskAverseTarget
solution3 = minimize(theHM.evalMetric, x0=0.6, method='COBYLA',
        constraints=[{'type': 'ineq', 'fun': lambda x: x}, {'type': 'ineq', 'fun': lambda x: 1-x}])
theHM.evalMetric(solution3.x)
print(solution3)
plotHorsetail(theHM, c='r', label='Very Risk Averse')
plt.xlim([-10, 5])
plt.ylim([0, 1])
plt.xlabel('Quantity of Interest')
plt.legend(loc='lower left')
plt.plot()
plt.show()
Explanation: In the following code we setup a horsetail matching optimization using test problem 3, and then run optimizations under three targets: a standard target, a risk averse target, and a very risk averse target.
End of explanation
<END_TASK>