Advanced examples > Response surface modeling
Python
Create the following plotrsm.py script:
Copy
from amesim import *
import scipy, pylab
import numpy
sname = 'scrdemo3'
thetascale_range1 = numpy.arange(0.5,1.5,0.01)
outangle_name = amegetvarnamefromui(sname, 'theta@rotaryload2ports')[0]
thetascale_name = amegetparamnamefromui(sname, 'k@gain')[0]
maxangle_rsmdata = []
# For each available RSM file
for filename in ('secondorder.rsm', 'thirdorder.rsm'):
# Read the first RSM in the .rsm file
M = scipy.matrix(amersmreadrsm(filename, 1))
# Evaluate the RSM at each point in thetascale_range1
maxangle_rsmdata.append([])
for thetascale in thetascale_range1:
dim = max(M.shape)
if dim <= 2:
# if the RSM order is less than or equal to 2
V = scipy.matrix(amersmcreatevec([thetascale],1))
resp = V*(M*V.T)
else:
# if the RSM order is greater than 2
V = scipy.matrix(amersmcreatevec([thetascale],dim-1))
resp = M*V.T
maxangle_rsmdata[-1].append(resp[0,0])
# Perform simulation for some values in the study range
thetascale_range2 = numpy.arange(0.5,1.5,0.1)
maxangle_data = []
for thetascale in thetascale_range2:
# Set the input parameter to the desired value
ameputp(sname,thetascale_name,thetascale)
# Perform simulation
amerunsingle(sname)
#Get result variable max value during simulation
[time_data, outangle_data], names = ameloadvarst(sname, [outangle_name])
maxangle_data.append(max(outangle_data))
# Graphically compare results with 2nd order and 3rd order RSM
pylab.plot(thetascale_range1, maxangle_rsmdata[0],'b', thetascale_range1,
maxangle_rsmdata[1], 'g',thetascale_range2, maxangle_data, 'rD')
pylab.grid(True)
pylab.xlabel(thetascale_name)
pylab.title('maximum of '+outangle_name)
pylab.legend(('2nd order RSM','3rd order RSM','simulation'))
pylab.show()
When you execute the script the graphic output is as follows:
Figure 37: Script result
Source: https://docs.sw.siemens.com/en-US/doc/254352342/PL20250521841123434.amesim_collection.Scripting/xid1133471 · retrieved 2026-07-17