Engineering Workshop 2 (Beee1313) : Lab 1: Matlab For Engineering Application On Arithmetic Operation
Engineering Workshop 2 (Beee1313) : Lab 1: Matlab For Engineering Application On Arithmetic Operation
[email protected],
LESSON OUTCOMES
At the end of this lesson, you should be able to:
• Familiarize with MATLAB environment.
• Perform simple arithmetic operations using MATLAB.
• Define, use, express constant and assign values to variables using MATLAB as a
calculator.
• Write and execute simple MATLAB commands and functions.
• Write simple MATLAB commands for engineering applications.
INTRODUCTION TO MATLAB
1. MATLAB is acronym for MATrix LABoratory which is developed by MathWorks.
2. The software has been widely adopted by academicians in the engineering
field due to:
i. A load of built-in fuction for engineering application which reduce
programming time.
ii. The great visualisation capabilities that is suitable for presenting result
obtained.
MATLAB ENVIRONMENT
1. Start MATLAB by clicking double left clicking the MATLAB desktop icon.
2. The program will takes a while to load and during the process a splash screen
will be display.
3. By default, MATLAB displays a desktop interface with the following principal
components:
• The Command Window is to enter commands.
• The Workspace browser is to display the variables.
• The Current Folder browser is to display current files.
• The Command History is the record of previous works.
MATLAB ENVIRONMENT
Workspace:
display the
Current Folder: variables
display current Command Window: enter commands.
files
Command
History: record
previous works.
2. The first step is to solve the problem is to identify the suitable equation. In this
case, the equation required is undoubtedly the most well known among the
Electronic Engineering students, the Ohm’s Law as expressed in Eq. (3):
𝑉 = 𝐼𝑅 (3)
where:
𝑉 is Voltage
𝐼 is Current
𝑅 is Resistance
MATLAB APPLICATION
3. The second step is to determine suitable name to represents all the variables. In
this case:
• V will be for Voltage
• I will be for Current, and
• R will be for Resistance
4. The third step is to determine the input and output variables. Input variables are
variables which values are known, while output variables are which value need to
be find. Thus:
• 𝐼 and 𝑅 are input variables
• 𝑉 is the output variable
MATLAB APPLICATION
6. The fourth step is to write the command to represent the input variables and
assign the respective values. Therefore:
>> I = 4.8, R = 50
7. The last step is to write the command that represent the mathematical equation.
In this case, the Ohm’s law can expressed as follows:
>> V = I * R
8. You should obtain 240 V as the final answer.
MATLAB APPLICATION
9. Let us look at another electrical problem as shown below:
Given a formula that express the relationship of the electromagnetic force of a solenoid coil
as shown below:
𝑚𝑐 × 𝐴(𝑛 × 𝑖)2
𝐹=
2𝑙 2
where:
𝐹is Force,
𝑖 is Current,
𝑙 is Length of the gap between the solenoid and a piece of metal,
𝐴 is Area,
𝑛 is Number of turns,
𝑚𝑐 is the magnetic constant of 4𝜋x 10-7.
Find the electromagnetic force of the solenoid coil for the given parameters: 𝑖 = 10A, 𝑙 =
0.01m, 𝐴 = 0.25𝑚2 , and 𝑛 = 1000 turns.
MATLAB APPLICATION
10. Applying the same method as mentioned earlier:
Given a formula that express the relationship of the
Step 1: Identify suitable formula electromagnetic force of a solenoid coil as shown below:
Step 2: Determine suitable name for all variables 𝑚𝑐 × 𝐴(𝑛 × 𝑖)2
𝐹=
Step 3: Identify input and output variables 2𝑙 2
where:
Variable names: output variables 𝐹is Force,
• F is Force 𝑖 is Current,
• i is Current 𝑙 is Length of the gap between the solenoid and a piece of metal,
• l is Length input variables 𝐴 is Area,
• A is Area 𝑛 is Number of turns,
• n is Number of turns 𝑚𝑐 is the magnetic constant of 4𝜋x 10-7.
• mc is Magnetic constant
Step 4: Write commands for inputs with the values Find the electromagnetic force of the solenoid coil for the given
parameters: 𝑖 = 10A, 𝑙 = 0.01m, 𝐴 = 0.25𝑚2 , and 𝑛 = 1000
>> i = 10, l = 0.01, A = 0.25, n = 1000
turns.
>> mc = 4 * pi * power(10,-7)
Step 5: Write commands for the formula >> F = (mc * A * (n * i)^2)/(2 * l^2)
MATLAB APPLICATION
11. Most of the time, we want the user to input the input variables. This can be
achieve by using the input command.
12. For example, i = input(‘Please insert the current:‘) where the
Command Window will display Please insert the current and once
the user insert the value and press enter, the value will be stored in variable i.
13. Let us takes the previous problem and rewrite the commands to allow user to
insert the input variables:
>> i = input(‘Enter the current value: ‘)
>> l = input(‘Enter the length value: ‘)
>> A = input(‘Enter the Area value: ‘)
>> n = input(‘Enter the value of the Number of turns: ‘)
>> mc = 4 * pi * power(10,-7)
>> F = (mc * A * (n * i)^2) / (2 * l^2)
MATLAB APPLICATION
14. Figure 9 shows the expected outcome of the Command Window:
Write a program that accepts values of Resistor, 𝑟 and Voltage, 𝑉𝑠 from user. Based on the
values of 𝑟 and 𝑉𝑠 obtained, the program returns the value of Current, 𝑖 according to the
formula derives from Ohm’s Law.
SUMMARY
What we have learned?
• MATLAB environment: MATLAB layout, important short cuts,
and accessing Help Documentation
• Define, use, express constant and assign values to variables
Write and execute simple MATLAB commands and functions
for solving mathematical equation
• Write MATLAB commands for solving Ohm’s Law, and RC
circuit.
REFERENCES
1. K. Bennett, MATLAB: Applications for the Practical Engineer, London: InTechOpen
Limited, 2014.
2. H. Moore, MATLAB for Engineers (5th Edition), London: Pearson, 2017.
3. M. Sadiku, C. Alexander, Fundamentals of Electrical Circuits (5th Edition), Columbus:
McGraw-Hill Education, 2012.