Professional Documents
Culture Documents
OBJECTIVES
To provide supplementary information on arrays.
To enable the students to ask for input and display output in their programs.
GRADING SYSTEM
INSTRUCTIONS
A. More on Arrays and Array Operations
1. Try the following commands:
>> w=zeros(5) <Enter>
>> x=zeros(4,3) <Enter>
>> y=ones(6) <Enter>
>> z=ones(size(x)) <Enter>
>> a=eye(5) <Enter>
>> b=eye(3,4) <Enter>
>> length(x) <Enter>
>> size(b) <Enter>
>> arr1=[1:8] <Enter>
>> arr1(5:end) <Enter>
2. Matrix Operations
>> x=rand(3,4) <Enter>
>> y=rand(4,5) <Enter>
>> x*y <Enter>
>> y*x <Enter>
>> a=10*rand(3,2) <Enter>
>> b=10*rand(3,2) <Enter>
>> a.*b <Enter>
>> b.^a <Enter>
B. Documentation
script3a.m
%This program calculates the area of a circle
C. Input function
1. Try the following:
Note: %d and %f are called placeholders that indicate the type of value that is being printed.
%d integers (it actually stands for decimal integer)
%f floats
%c single characters
%s strings
b. translatethis.m
On average, people in a region spend 8 to 10% of their income on food. Write a script that will prompt
the user for an annual income. It will then print the range that would typically be spent on food annually.
Run your script and put P205,000 as the annual income.
c. quadraticformula.m
Write a program that would ask for the values of a, b, and c, then calculate for x, where
−b ± √ b2−4 ac
x=
2a
Run your script and input a = 2, b = -10, c = 12
d. temperature.m
If C and F are Celsius and Fahrenheit temperatures respectively, the formula for conversion from
Celsius to Fahrenheit is F = 9C/5 + 32.
Write a script that will ask you for the Celsius temperature and display the equivalent Fahrenheit
temperature.Try it out on values 0, 100, -40 and 37.
Machine
3 (Input and Output) Score
Problem #
Name Section
1.
a. Command:
b. Command:
c. Command:
d. Command:
2.
a. areaofrectangle.m
Command Window:
Script:
b. translatethis.m
Command Window:
Script:
c. quadraticformula.m
Command Window:
Script:
d. temperature.m
Command Window:
Script: