Skip to main content
Engineering LibreTexts

2.15.1: More Exercises

  • Page ID
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

      Exercise \(\PageIndex{1}\) Volume of a Cobblestone

      A cobblestone (guijarro) is shoebox-shaped.

      Create a .m-file (a Matlab script) to compute the volume of a cobblestone.

      Set these variables:

      cobblestone_length = 9

      cobblestone_width = 5

      cobblestone_height = cobblestone_width

      Then use these variables to compute the volume of this cobblestone.

      Test your .m file.


      The answer is not given here.


      Exercise \(\PageIndex{2}\) Voltage divider

      This is a schematic of a voltage divider.

      Voltage Divider,

      The formula is: Vout = Vin*(R2/(R1+R2))

      (1 pt) Write a MATLAB m-file script that computes the output of a voltage divider. 

      Your file name should be: Voltage_divider_Name.m, where you replace "Name" with your name.

      (1 pt) The following variables are set outside of your script before running your script. They are preconditions (inputs) to your script file. Your file script should have these inputs documented by the following comments:

      % Vin = the input voltage

      % R1 = resistance of the 1st resistor

      % R2 = resistance of the 2nd resistor

      (1 pt) In your script, also specify this post condition (output) as a comment:

      % Vout = the output voltage.

      (2 pts) In your script calculate the output voltage with this formula:

      Vout = Vin*(R2/(R1+R2))

      (6 pts) Write a 2nd MATLAB m-file script that tests your file.

      Its name should be Voltage_divider_test_Name.m, where you replace "Name" with your name.

      This file sets each of these sets of inputs and runs (calls) your file:


      Vin = 5 volts;

      R1 = 2000 Ohms;

      R2 = 8000 Ohms

      Voltage_divider_Name  % This line runs (calls) your script.


      Vin = 10 volts;

      R1 = 5000 Ohms;

      R2 = 5000 Ohms

      Voltage_divider_Name  % This line runs (calls) your script.


      Write the code code and test it.

      This page titled 2.15.1: More Exercises is shared under a CC BY-NC-SA 4.0 license and was authored, remixed, and/or curated by Carey Smith.

      • Was this article helpful?