Creating Custom Components and Libraries
Explore examples that illustrate creating custom components and libraries.
Related Information
Featured Examples
Vehicle HVAC System
Models moist air flow in a vehicle heating, ventilation, and air conditioning (HVAC) system. The vehicle cabin is represented as a volume of moist air exchanging heat with the external environment. The moist air flows through a recirculation flap, a blower, an evaporator, a blend door, and a heater before returning to the cabin. The recirculation flap selects flow intake from the cabin or from the external environment. The blender door diverts flow around the heater to control the temperature.
Aircraft Environmental Control System
Models an aircraft environmental control system (ECS) that regulates pressure, temperature, humidity, and ozone (O3) to maintain a comfortable and safe cabin environment. Cooling and dehumidification are provided by the air cycle machine (ACM), which operates as an inverse Brayton cycle to remove heat from pressurized hot engine bleed air. Some hot bleed air is mixed directly with the output of the ACM to adjust the temperature. Pressurization is maintained by the outflow valve in the cabin. This model simulates the ECS operating from a hot ground condition to a cold cruise condition and back to a cold ground condition.
PEM Fuel Cell System
Model a proton exchange membrane (PEM) fuel cell stack with a custom Simscape™ block. The PEM fuel cell generates electrical power by consuming hydrogen and oxygen and producing water vapor. The custom block represents the membrane electrode assembly (MEA) and is connected two separate moist air networks: one for the anode gas flow and one for the cathode gas flow.
PEM Electrolysis System
Model a proton exchange membrane (PEM) water electrolyzer with a custom Simscape™ block. The PEM electrolyzer consumes electrical power to split water into hydrogen and oxygen. The custom block represents the membrane electrode assembly (MEA) and is connected to a thermal liquid network and two separate moist air networks: the thermal liquid network models the water supply, the anode moist air network models the oxygen flow, and the cathode moist air network models the hydrogen flow.
Ultracapacitor Energy Storage with Custom Component
Use the Simscape™ example library Capacitors_lib. The model is constructed using components from the example library. The circuit charges an ultracapacitor from a constant 0.05 amp current source, and then delivers a pulse of current to a load. The ultracapacitor enables a much higher current to be delivered than is possible directly from the current source. The library contains capacitor models with different levels of fidelity to allow exploration of the effect of losses and nonlinearity.
Transmission Line
A lumped parameter transmission line model. It is built from a custom Simscape™ component that defines a single T-section segment. The model concatenates 50 segments, each of length 0.1m, thereby modeling a 5m length of coaxial cable. The transmission delay can be observed from the simulation results.
Engine Cooling System
Model a basic engine cooling system using custom thermal liquid blocks. A fixed-displacement pump drives water through the cooling circuit. Heat from the engine is absorbed by the water coolant and dissipated through the radiator. The system temperature is regulated by the thermostat, which diverts flow to the radiator only when the temperature is above a threshold.
Brayton Cycle (Gas Turbine) with Custom Components
Models a gas turbine auxiliary power unit (APU) based on the Brayton Cycle. The Compressor and Turbine blocks are custom components based on the Simscape™ Foundation Gas Library. The power input to the system is represented by heat injection into the combustor; actual combustion chemistry is not modeled. A single shaft connects the compressor and the turbine so that the power from the turbine drives the compressor. The APU is a free turbine that further expands the exhaust stream to produce output power.
Rankine Cycle (Steam Turbine)
Models a steam turbine system based on the Rankine Cycle. The cycle includes superheating and reheating to prevent condensation at the high-pressure turbine and the low-pressure turbine, respectively. The cycle also has regeneration by passing extracted steam through closed feedwater heaters to warm up the water and improve cycle efficiency.
Battery Cell with Custom Electrochemical Domain
Use the Simscape™ example library ElectroChem_lib. In the model Fe3+ ions are reduced to Fe2+, and Pb is oxidized to Pb2+, thereby releasing chemical energy. The molar flow rate of lead ions is half that of the iron ions as two electrons are exchanged when Pb is oxidized to Pb2+. The chemical potential of the Pb source is by convention zero as it is a solid.
Lead-Acid Battery
Model a lead-acid battery cell using the Simscape™ language to implement the nonlinear equations of the equivalent circuit components. In this way, as opposed to modeling entirely in Simulink®, the connection between model components and the defining physical equations is more easily understood. For the defining equations and their validation, see Jackey, R. "A Simple, Effective Lead-Acid Battery Modeling Process for Electrical System Component Selection", SAE World Congress & Exhibition, April 2007, ref. 2007-01-0778.
Lithium Battery Cell - One RC-Branch Equivalent Circuit
Model a lithium cell using the Simscape™ language to implement the elements of an equivalent circuit model with one RC branch. For the defining equations and their validation, see T. Huria, M. Ceraolo, J. Gazzarri, R. Jackey. "High Fidelity Electrical Model with Thermal Dependence for Characterization and Simulation of High Power Lithium Battery Cells," IEEE International Electric Vehicle Conference, March 2012.
Lithium Battery Cell - Two RC-Branch Equivalent Circuit
Model a lithium cell using the Simscape™ language to implement the elements of an equivalent circuit model with two RC branches. For the defining equations and their validation, see T. Huria, M. Ceraolo, J. Gazzarri, R. Jackey. "High Fidelity Electrical Model with Thermal Dependence for Characterization and Simulation of High Power Lithium Battery Cells," IEEE International Electric Vehicle Conference, March 2012.
Lithium-Ion Battery Pack with Fault Using Arrays
Simulate a battery pack that consists of multiple series-connected cells. It also shows how you can introduce a fault into one of the cells to see the impact on battery performance and cell temperatures. The battery pack is modeled in Simscape™ language by connecting cell models in series using arrays. You can represent the fault by defining different parameters for the faulty cell.
Variable Transport Delay
Use Simscape™ to model a variable transport delay. The Transport Delay block models signal propagation through media moving between the Input and the Output terminals. The media velocity may vary, thus it is specified through the block port. The distance between the terminals as well as the initial output are constant and they are specified as block parameters.
Asynchronous PWM Voltage Source
How the Simscape™ Foundation Library PS Asynchronous Sample & Hold block can be used to build components with more complex behaviors. The model implements a controllable PWM voltage source where the PWM on-time (the duty cycle) is proportional to the physical signal input u.
Discrete-Time PWM Voltage Source
How the discrete-time Simscape™ Foundation Library PS Counter block can be used to build components with more complex behaviors. The model implements a controllable PWM voltage source where the PWM on-time (the duty cycle) is proportional to the physical signal input u.
Actuation Circuit with Custom Pneumatic Components
Model a controlled actuator using simplified custom pneumatic components. There are two across variables, defined as pressure and temperature, and two through variables, defined as mass flow rate and heat flow rate. The simplified approach means that every node in the circuit must have a volume of gas associated with it. This physical volume of gas in the circuit is represented by the Constant Volume Pneumatic Chamber blocks, the Pneumatic Piston Chamber blocks, and the Pneumatic Atmospheric Reference block. Conversely, the Foundation Library gas components require no such connection rules at every node. See the Pneumatic Actuation Circuit example for a more capable way of modeling pneumatic systems using Foundation Library gas components.
Simscape Functions
Write Simscape™ functions to compute numerical values with Simscape expressions and how to use Simscape functions to improve code reuse across components. The top two Simscape component blocks ( inside the "Use no Simscape functions" box ) are respectively created using two Simscape component files. Comparing these two component files, similar Simscape expressions can be observed on the right hand side of the equation to compute numerical values, which is essentially a modification of exp(i) to provide protection for large magnitude of i. Such expressions are common in standard diode modeling. Using Simscape functions, such expressions are abstracted out into a Simscape function file, and their usages inside the component files are replaced by calls to such Simscape functions. The bottom two Simscape component blocks ( inside the "Use Simscape functions" box ) are created using component files using Simscape functions.
Mass on Cart Using an Ideal Hard Stop
A cart bouncing between the two ends of an ideal hard stop, while a mass slides freely on top of it. The friction between the mass and cart is modeled using an ideal, modechart-based friction block, while the hard stop is modeled using instantaneous modes and entry actions. When the cart hits the bounds of the hard stop, the impulsive force is propagated to the mass above, causing it to be displaced as it transitions from static to dynamic friction modes.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)