Lab 3
Lab 3
Lab 3
Objective
To perform various operations using the m-script file.
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.
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
Result:
Enter the 1st Value = 20
Enter the 2nd Value = 15
sum =
35
subtract =
prod =
300
q=
1.3333
r=
Result:
Enter Your Salary in Rs= 1500
A=
1500
Dollars =
14.6242
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