ot.Log.Show(ot.Log.NONE) # prepare some data formulas = ['cos(x1 + x2)', '(x2 + 1) * exp(x1 - 2 * x2)'] model = ot.SymbolicFunction(['x1', 'x2'], formulas) # center of the approximation x0 = [-0.4, -0.4] # drawing bounds a=-0.4 b=0.0 # %% # create a linear (first order) Taylor approximation algo = ot.LinearTaylor(x0, model) algo.run() responseSurface = algo.getMetaModel() # %% # plot 2nd output of our model with x1=x0_1 graph = ot.ParametricFunction(responseSurface, [0], [x0[1]]).getMarginal(1).draw(a, b) graph.setLegends(['taylor']) curve = ot.ParametricFunction(model, [0], [x0[1]]).getMarginal(1).draw(a, b).getDrawable(0) curve.setColor('red') curve.setLegend('model') graph.add(curve) graph.setLegendPosition('topright') view = viewer.View(graph) # %%
#! /usr/bin/env python from __future__ import print_function import openturns as ot eps = 0.2 # Instance creation myFunc = ot.SymbolicFunction( ['x1', 'x2'], ['x1*sin(x2)', 'cos(x1+x2)', '(x2+1)*exp(x1-2*x2)']) center = ot.Point(myFunc.getInputDimension()) for i in range(center.getDimension()): center[i] = 1.0 + i myTaylor = ot.LinearTaylor(center, myFunc) myTaylor.run() responseSurface = ot.Function(myTaylor.getResponseSurface()) print("myTaylor=", repr(myTaylor)) print("responseSurface=", repr(responseSurface)) print("myFunc(", repr(center), ")=", repr(myFunc(center))) print("responseSurface(", repr(center), ")=", repr(responseSurface(center))) inPoint = ot.Point(center) inPoint[0] += eps inPoint[1] -= eps / 2 print("myFunc(", repr(inPoint), ")=", repr(myFunc(inPoint))) print("responseSurface(", repr(inPoint), ")=", repr(responseSurface(inPoint)))