<jupyter_start><jupyter_text>AddSubtractComp[AddSubtractComp](../../../_srcdocs/packages/components/add_subtract_comp.htmlopenmdao-components-add-subtract-comp-py) performs elementwise addition or subtraction between two or more compatible inputs.  It may be vectorized to provide the result at one or more points simultaneously.$$    result = a * \textrm{scaling factor}_a + b * \textrm{scaling factor}_b + c * \textrm{scaling factor}_c + ...$$ AddSubtractComp ConstructorThe call signature for the `AddSubtractComp` constructor is:```{eval-rst}    .. automethod:: openmdao.components.add_subtract_comp.AddSubtractComp.__init__        :noindex:``` Using the AddSubtractCompThe `add_equation` method is used to set up a system of inputs to be added/subtracted (with scaling factors).Each time the user adds an equation, all of the inputs and outputs must be of identical shape (this is a requirement for element-wise addition/subtraction).The units must also be compatible between all inputs and the output of each equation. Method Signature```{eval-rst}    .. automethod:: openmdao.components.add_subtract_comp.AddSubtractComp.add_equation        :noindex:``` AddSubtractComp ExampleIn the following example AddSubtractComp is used to add thrust, drag, lift, and weight forces. Note the scaling factor of -1 for the drag force and weight force.<jupyter_code>import numpy as np
import openmdao.api as om

n = 3

p = om.Problem()
model = p.model

# Construct an adder/subtracter here. create a relationship through the add_equation method
adder = om.AddSubtractComp()
adder.add_equation('total_force', input_names=['thrust', 'drag', 'lift', 'weight'],
                   vec_size=n, length=2, scaling_factors=[1, -1, 1, -1], units='kN')
# Note the scaling factors. we assume all forces are positive sign upstream

# The vector represents forces at 3 time points (rows) in 2 dimensional plane (cols)
p.model.add_subsystem(name='totalforcecomp', subsys=adder,
                      promotes_inputs=['thrust', 'drag', 'lift', 'weight'])

p.setup()

# Set thrust to exceed drag, weight to equal lift for this scenario
p['thrust'][:, 0] = [500, 600, 700]
p['drag'][:, 0] = [400, 400, 400]
p['weight'][:, 1] = [1000, 1001, 1002]
p['lift'][:, 1] = [1000, 1000, 1000]

p.run_model()

# Verify the results
expected_i = np.array([[100, 200, 300], [0, -1, -2]]).T
print(p.get_val('totalforcecomp.total_force', units='kN'))
from openmdao.utils.assert_utils import assert_near_equal

assert_near_equal(p.get_val('totalforcecomp.total_force', units='kN'), expected_i)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1185127807900852, 'fraction_numerical': 0.025948876839659178, 'mean_word_length': 4.951612903225806, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '110134', 'license': 'Apache-2.0', 'n_tokens_mistral': 844, 'n_tokens_neox': 775, 'n_words': 263, 'path': 'openmdao/docs/openmdao_book/features/building_blocks/components/add_subtract_comp.ipynb', 'repo_name': 'tong0711/OpenMDAO', 'size': '2582'}