11.5: Example- Adding Two Numbers

Fundamentals of MATLAB Programming · LibreTexts

0%

Contents

    Text

    Size
    100%
    Theme
    Typeface
    Line length
    Spacing

    From LibreTexts, under CC BY-NC-SA, as the source states it; its equations are written in TeX, which the PDF shows typeset. This page at LibreTexts.

    11.5: Example- Adding Two Numbers

    Let us begin with the simplest possible Simulink model: adding two numbers. This example is not exciting mathematically, but it is very useful because it teaches the basic workflow: choose blocks, connect blocks, set parameters, run the model, and view the result.

    The model will calculate 5 + 3.
    The output should be 8.
    

    Blocks needed:

    • Two Constant blocks
    • One Sum block
    • One Display block

    Build the model using these steps:

    1. Open a blank Simulink model.

    2. From Sources or Commonly Used Blocks, drag a Constant block into the model.

    3. Copy the constant block so you have two constant blocks. You can do this by either dragging a second constant block into the model or by right-clicking the first constant block and dragging it to create a duplicate.

    4. Double-click the first Constant block and set its value to 5.

    5. Double-click the second Constant block and set its value to 3.

    6. From Math Operations or Commonly Used Blocks, drag a Sum block into the model.

    7. Connect both Constant blocks to the Sum block.

    8. From Sinks, drag a Display block into the model.

    9. Connect the Sum block output to the Display block.

    10. Set the Stop Time to 0 because nothing in this model changes with time.

    11. Save the model and click Run.

    clipboard_e209653203372f24edeb8417137eaf7fe.png

    The Display block should show the result 8. In this model, the values do not depend on time, so setting the Stop Time to 0 is reasonable. Later, when we work with signals that change with time, we will use a longer stop time, such as 10 or 15 seconds.

    Showing and renaming block names

    If a block name is hidden, click the block and use the small menu below it to show the block name. To rename a block, click the block label and type a more meaningful name. Meaningful labels are helpful when your models become larger.

    clipboard_e025cb816f2aea7e81c5fda8f34475680.png


    This page titled 11.5: Example- Adding Two Numbers was last modified on Tue, 30 Jun 2026 02:11:49 GMT and is shared under a CC BY-NC-SA license and was authored, remixed, and/or curated by Zara Noroozi.