0% found this document useful (0 votes)
175 views5 pages

Lab 3

The document describes a MATLAB lab session on performing arithmetic operations using m-script files. It includes objectives, commands used, and procedures for addition, subtraction, multiplication, division, and conversions between units like dollars, inches and centimeters. Users are prompted to input values, and programs demonstrate arithmetic operations and printing results on these input values using MATLAB commands.

Uploaded by

SYED HAMZA WAJID
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
175 views5 pages

Lab 3

The document describes a MATLAB lab session on performing arithmetic operations using m-script files. It includes objectives, commands used, and procedures for addition, subtraction, multiplication, division, and conversions between units like dollars, inches and centimeters. Users are prompted to input values, and programs demonstrate arithmetic operations and printing results on these input values using MATLAB commands.

Uploaded by

SYED HAMZA WAJID
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

LAB SESSION-3

Objective
To perform various operations using the m-script file.

MATLAB Commands Used:


1) input (for entering numeric values)
2) sqrt (for finding square root of polynomial)
3) + (for performing addition)
4) - (for performing subtraction)
5) * (for performing multiplication)
6) [q,r]=deconv (for performing division in terms of quotient & remainder)

Procedure:
1-Arithmetic Operations and Arithmetic Operators
 Open the script file.
 First of all provide an input command in order to allow the programmer to provide
desired values.
 Then apply the +, - and * command for performing addition, subtraction and
multiplication of desired values.
 On the matlab screen, you shall be asked to provide first variable, and then second
variable and then press ENTER to proceed to the desired results.

Q. Write a program to perform the arithmetic operations by using all the


arithmetic operators. Also print the results on the screen.

Programme:
x=input('Enter the 1st Value = ');
y=input('Enter the 2nd Value = ' );
sum= x+y
subtract=x-y
prod=x*y
Result:
Enter the 1st Value = 25
Enter the 2nd Value = 26

sum =

51

subtract =

-1

prod =

650

2-Addition, Multiplication, Quotient, Remainder


 Open the script file.
 First of all provide an input command to provide desired values.
 Then apply the +, -, * and [q,r]=deconv command for performing addition, subtraction,
multiplication and obtaining quotient and remainder of desired values.
 On the matlab screen, you shall be asked to provide first variable, and then second
variable and then press ENTER to proceed to the desired results.
Q. Write and run a program that prints the sum, difference, product,
quotient and remainder of two integers. Initialize the integers with
values as inputs by the user.
Programme:
x=input('Enter the 1st Value = ');
y=input('Enter the 2nd Value = ' );
sum= x+y
subtract=x-y
prod=x*y
[q,r]=deconv(x,y)

Result:
Enter the 1st Value = 20
Enter the 2nd Value = 15

sum =

35

subtract =

prod =

300
q=

1.3333

r=

3-Division with Single Input Value


Procedure:
 Open the script file.
 First of all provide an input command in order to allow the programmer to provide
desired value.
 Apply / command to divide the desired value by an already known or set variable.
 MatLab would display to provide an input value.
 Press ENTER and the required answer would be displayed on the screen.

Q. Write a program to take input of “your expected salary” in Rs. And


then convert it into dollars as your salary in Dollars. ( 1 Dollar = 102.57)
Programme:
A =input('Enter Your Salary in Rs= ')
Dollars= A / 102.57

Result:
Enter Your Salary in Rs= 1500

A=

1500
Dollars =

14.6242

4-Multiplication with Single Input Value

Procedure:
 Open the script file.
 First of all provide an input command in order to allow the programmer to provide
desired value.
 Apply * command to multiply the desired value by an already known or set variable.
 MatLab would display to provide an input value.
 Press ENTER and the required answer would be displayed on the screen.

Q. Write a program that uses input from user in ‘inches’ and display the
result in centimeters (one inch = 2.54 centimeters).

Programme:
B=input('Enter Your Value in Inches= ');
Centimeter=B * 2.54

Result:
Enter Your Value in Inches= 4

Centimeter =

10.1600

You might also like