Create and Apply Constraints
This example shows how to create and apply constraints to a design using Model-Based Calibration Toolbox™ command-line interface.
Create a Design
Create a Full Factorial design, because this will show the constraint boundaries as clearly as possible. Create the design from inputs. For simplicity, only 2 inputs (speed and load) are used.
inputs = mbcmodel.modelinput(... 'Symbol', {'N','L'},... 'Name', {'SPEED','LOAD'},... 'Range', {[500 6000],[0.0679 0.9502]}); design = CreateDesign( inputs, 'Type', 'Full Factorial' ); design = Generate( design, 'NumberOfLevels', [50 50] ); % design has a Constraints property, initially this is empty. constraints = design.Constraints
constraints =
Create a Linear Constraint
cLinear = CreateConstraint( design, 'Type', 'Linear' ); cLinear.A = [-2.5e-4, 1]; cLinear.b = 0.25; cLinear
cLinear = Linear design constraint: -0.00025*N + 1*L <= 0.25
design.Constraints = cLinear; design = Generate(design);
Show Constraint
Plot the points to show the linear constraint.
Scatter2D(design, 1, 2);
title( 'Linear Constraint' );![Figure contains an axes object. The axes object with title Linear Constraint, xlabel SPEED (N) [-], ylabel LOAD (L) [-] contains a line object which displays its values using only markers.](../../examples/mbc/win64/UsingConstraintsExample_01.png)
Create a 1D Table Constraint
cTable1d = CreateConstraint( design, 'Type', '1D Table' ); cTable1d.Table = [0.9 0.5]; cTable1d.Breakpoints = [500 6000]; cTable1d
cTable1d = 1D Table design constraint: L(N) <= Lmax
design.Constraints = cTable1d; design = Generate(design);
Show Constraint
Plot the points to show the 1D Table constraint.
Scatter2D( design, 1, 2 );
title( '1D Table Constraint ' );![Figure contains an axes object. The axes object with title 1D Table Constraint, xlabel SPEED (N) [-], ylabel LOAD (L) [-] contains a line object which displays its values using only markers.](../../examples/mbc/win64/UsingConstraintsExample_02.png)
Combining Constraints
Constraints is an array of the constraints to apply.
design.Constraints = [cLinear, cTable1d]; constraints = design.Constraints
constraints = Linear design constraint: -0.00025*N + 1*L <= 0.25 1D Table design constraint: L(N) <= Lmax
design = Generate(design);
Show Constraint
Plot the points to show both constraints.
Scatter2D( design, 1, 2 );
title( 'Linear and 1D Table Constraint ' );![Figure contains an axes object. The axes object with title Linear and 1D Table Constraint, xlabel SPEED (N) [-], ylabel LOAD (L) [-] contains a line object which displays its values using only markers.](../../examples/mbc/win64/UsingConstraintsExample_03.png)