Beruflich Dokumente
Kultur Dokumente
3ECE-E
1. You want to compare to sine, cosine and tangent functions with random arguments. The
goal is to create a script file that computes for the sine, cosine and tangent values of a 5-
element row vector which consists of random values from 0 to 360 degrees. The values
of the vector are to be assigned within the script in a variable called random_degrees.
Store the sine, cosine and tangent values in a 4x5 matrix (2nd, 3rd and 4th row) called
sincostan. Save the script as trigo_solver.
Sample Run:
>> trigo_solver
random_degrees =
sincostan =
MATLAB Code:
random_degrees =
58 242 264 261 24
sincostan =
58.00000 242.00000 264.00000 261.00000 24.00000
0.84805 -0.88295 -0.99452 -0.98769 0.40674
0.52992 -0.46947 -0.10453 -0.15643 0.91355
1.60033 1.88073 9.51436 6.31375 0.44523
1-1
YUMUL, JOHN ANTHONY M.
3ECE-E
Note:
The function should prompt the user to enter the size of the square matrix n is an input
argument.
The 3 matrices rand_mat, square_mat and cube_mat should be displayed when the
function is called.
Sample Run:
>> square_cube
This script generates 3 matrices rand_mat, square_mat and cube_mat.
Enter the size of the matrix: 3
n=
3
rand_mat =
0 -3 -2
-3 -8 -5
8 6 -2
square_mat =
0 9 4
9 64 25
64 36 4
cube_mat =
0 -27 -8
-27 -512 -125
512 216 -8
MATLAB Code:
This program will compute for the square and cube of the matrix of the random numbers
with a range of -10 to 10
Enter the size of the matrix = 3
rand_mat =
-9 -1 -5
1-2
YUMUL, JOHN ANTHONY M.
3ECE-E
4 7 9
-7 4 9
square_mat =
81 1 25
16 49 81
49 16 81
cube_mat =
-729 -1 -125
64 343 729
-343 64 729
3. A scientist measured the temperature in Manila every 3:00pm for a rainy week. His data
was saved in a spreadsheet and he plans to load it in MATLAB to perform some data
analysis.
Write a script called tempdataconverter which loads the spreadsheet data into a matrix.
Create a 4x7 matrix called temp_manila which contains the original data (1st and 2nd
row), and the measurements converted to degrees Fahrenheit (3rd row) and Kelvin (4th
row).
Note:
Download the spreadsheet here and place it in your MATLAB working directory.
Read the documentations for the function importdata.
9
(
℉= ℃ ×
5)+32
K=℃+ 273.15
Sample Run:
>> tempdataconverter
temp_manila =
MATLAB Code:
This program will convert the temperature given to kelvin and fahrenheit.
1-3
YUMUL, JOHN ANTHONY M.
3ECE-E
temp_manila =
1.0000 2.0000 3.0000 4.0000 5.0000 6.0000 7.0000
31.2000 30.5000 28.7000 29.1000 27.2000 28.3000 30.6000
88.1600 86.9000 83.6600 84.3800 80.9600 82.9400 87.0800
304.3500 303.6500 301.8500 302.2500 300.3500 301.4500 303.7500
<end>
Prepared by:
Mark O. Montances
Reviewed by:
Grace C. Bautista
Reference:
mongmontances.com/tutorials/
1-4