Professional Documents
Culture Documents
EXPERIMENT NO 3
Lab Title Array Operations, Linear equations, Scripts and Functions in MATLAB
Student Name: Umar Mustafa Reg. No: 200365
Objective:
LAB ASSESSMENT:
Data presentation
Experimental results
Conclusion
Date: Signature:
Lab Report: 3
Array Operations, Linear equations, Scripts and Functions in
MATLAB
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:
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
% 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
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