You are on page 1of 8

AIR UNIVERSITY

DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING

EXPERIMENT NO 3

Lab Title Array Operations, Linear equations, Scripts and Functions in MATLAB
Student Name: Umar Mustafa Reg. No: 200365

Objective:

LAB ASSESSMENT:

Excellent Good Average Satisfactory Unsatisfactory


Attributes
(5) (4) (3) (2) (1)
Ability to Conduct
Experiment
Ability to assimilate the
results
Effective use of lab
equipment and follows
the lab safety rules

Total Marks: Obtained Marks:

LAB REPORT ASSESSMENT:


Excellent Good Average Satisfactory Unsatisfactory
Attributes
(5) (4) (3) (2) (1)

Data presentation

Experimental results

Conclusion

Total Marks: Obtained Marks:


BCE-III-A Introduction to MATLAB

Date: Signature:

Department of Electrical and Computer Engineering

Computer Application in Engineering Design Lab

Lab Report: 3
Array Operations, Linear equations, Scripts and Functions in
MATLAB

Name: Umar Mustafa


Roll Number: 200365
Class: BCE-3A

Submitted To: Engr. M. Farooq Khan

Date: September 11th, 2021


2
Air University, Islamabad CAED Lab

Lab Tasks
Q1. Use all the array operators in the Pre-Lab on randomly generated inputs.
% Task 1:
A = randi([1,9],1,4)
B = randi([1,14],1,4)
A+B
A-B
A.*B
A.^2

OutPut:

3
BCE-III-A Introduction to MATLAB

Q2). Solve the following linear system of equations using backslash (\) operator

% Task 2:
A = [1 1 1 ; 1 2 0 ; 2 0 1];
B = [6 ; 5 ; 5];
C = A\B

OutPut:-

Q3. Solve the following linear system of equations using backslash (\) operator
% Task 3:
A = [1 3 -1 2 3 ; 1 2 -1 4 9 ; 3 -5 3 2 -1 ; 0 2 1 0 2 ; 1 -1 0 0 2];
B = [5;-3;7;-3;1];
C = inv(A)*B

OutPut:-

4
Air University, Islamabad CAED Lab

Q4). Alexa buys three mangoes, one apple and a dozen bananas for $2.36. Robb
buys two apples and a dozen mangoes for $5.26. Finn buys two bananas and three
apples for $2.77. How much do single pieces of each fruit cost?

% Task 4:
A = [3 1 12 ;12 2 0;0 3 2];
B = [2.36;5.26;2.77];
C = inv(A)*B

OutPut:

Mangoe = 0.29 D , Apple = 0.89 D and Banana = 0.05 D

Q5). Write a function file that converts temperature in degrees Fahrenheit (◦F) to

5
BCE-III-A Introduction to MATLAB

degrees Centigrade (◦C). Use input and fprintf commands to display a mix of text

and numbers. Recall the conversion formulation, C = 5/9 ∗ (F − 32).

% Task 5
Feh = input('Enter deg in F\n');
celsius = 5*(A-32)/9;
fprintf('%d Fahrenheit is = %d celsius\n',Feh,celsius)

OutPut:

Q6. Write a user-defined MATLAB function, with two input and two output
arguments that determines the height in centimeters (cm) and mass in kilograms
(kg) of a person from his height in inches (in.) and weight in pounds (lb).
▪ Determine in SI units the height and mass of a 5 ft.15 in. person who
weight 180 lb.
▪ Determine your own height and weight in SI units.

6
Air University, Islamabad CAED Lab

% Task 6:
function [cht , kwht] = bodyconversion ( fht , iht , lwht )
% Convert the weight from lb's to kg's and the height from ft and inches to cm's
% fht = height in feet
% iht = feet in inches
% lwht = weight in lbs

fht = input ( 'Enter your height in feet here: ' ) ;


iht = input ( 'Enter your height in inches here: ' ) ;
lwht = input ( 'Enter your weight in pounds here: ' ) ;

% Conversion formula for feet to inches is in = ft * 12


convertin = fht * 12 ;
% conversion formula from inches to centimeters is: cm = inch * 2.54
% Where height in inches includes feet.
cht = ( convertin + iht ) * 2.54 ;
% convert weight from lbs to kg formula is 1kg = 2.205 lbs
kwht = lwt / 2.205 ;
fprintf ( '%.5 ft, %5 in is %.5cm\n' , fht , iht , cht ) ;
fprintf ( '%.5 lbs is %.5 kg\n' , lwht , kht )

Bodyconversion:
Enter your height in feet here: 5.7
Enter your height in inches here: 68.4
Enter your weight in pounds here: 127.28

OutPut:

7
BCE-III-A Introduction to MATLAB

You might also like