Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Sheet Chapter (1) Introduction To MATLAB: Section (A)

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Sheet Chapter (1)

Sheet Chapter (1)


Introduction to MATLAB
Section (A)
1) Type the following expressions into MATLAB at the command prompt, and observe the results
and the workspace window:
1. a=5 + 2 2. b=5*2 3. A=5/2
4. B=3 + 2* (4 + 3) 5. x1=2.54*8/2.6 6. Y=6.3 - 2.1045
7. f1=3.6^2 8. f2=1+ 2^2 9. f3=sqrt(5)
10. f4=cos(pi) 11. D=[1,2,3] 12. K=[1,2,3;1,2,3]
2) In previous example write the directory folder that MATLAB currently worked on and change it
to desktop directory:
3) Run the MATLAB program and using the document window create the following
A=10 B=[10,20,30,40,50] C=[10;20;30;40;50]
Then do the following
F1=A*B F=A*C F3=B*C
Change the name of variable F to F2. Also, change the C matrix to be 10 elements with the same
used step. Finally, create a new variable “B” from the document window and illustrate your
observation.
4) Create a new folder at your computer desktop “Matlab2year”. Create a new M-file program to do
the required in Q-3.
5) Which of the following names are allowed in MATLAB? Make your predictions, then test them
with the isvarname, iskeyword, and which commands.
1. test 2. Test 3. if
4. my-book 5. my_book
6. Thisisoneverylongnamebutisitstillallowed? 7. 1stgroup
8. group_one 9. zzaAbc 10. z34wAwy?12#
11. sin 12. Log
6) Run the diary function with a file name “excercies_1_3” and then do the following
A=10 B=[10,20,30,40,50] C=[10;20;30;40;50]
Then display the content of the excercies_1_3 file
Display the content of the workspace, then save its content in a file “my_workspace1” and save
the content of variables B and C only in a file “variables_B_C”
Clear the command window and workspace then load “my_workspace1” file and do the following
D=B*C

1
Computer Applications

7) Create M-file to print a table of time and voltages v1 and v2, where time t=0:4π with a step of
0.005, voltage v1=v1max sin(t) and voltage v2= v2max sin(2t). Plot the two voltages with time.
8) Create a vector x from −2 to +2 with an increment of 1. Your vector should be x = [−2, −1, 0, 1,
2]
a. Find the absolute value of each member of the vector.
b. Find the square root of each member of the vector.
c. Find the size of matrix x
9) Find the square root of both −3 and +3.
a. Use the sqrt function.
b. Use the nthroot function. (write your comment)
c. Raise −3 and +3 to the ½ power. (How do the results vary?)
10) Create a vector x from −9 to 12 with an increment of 3.
a. Find the result of x divided by 2.
b. Find the remainder of x divided by 2.
c. Find ex.
d. Find ln(x) (the natural logarithm of x).
e. Find log10 (x) (the common logarithm of x). Explain your results.
f. Use the sign function to determine which of the elements in vector x are positive.
11) Calculate the following:
a. sin(2θ) for θ = 3π.
b. cos(θ ) for 0 ≤ θ ≤ 2π; let π change in steps of 0.2 π.
c. sin−1(1).
d. cos−1(x) for −1 ≤ x ≤1; let x change in steps of 0.2.
e. Find the cosine of 45°.
- Convert the angle from degrees to radians, and then use the cos function.
- Use the cosd function.
f. Find the angle whose sine is 0.5. Is your answer in degrees or radians?
12) Consider the following matrix:

a. What is the maximum value in each column?


b. In which row does that maximum occur?
c. What is the maximum value in each row?
d. In which column does the maximum occur?
e. What is the maximum value in the entire table?
f. Creat a second matrix y with the same dimension with random values between 0 and 100
and find the matrix that contain the maximum values from the corresponding position in
matrix x and y.

2
Sheet Chapter (1)

13) Consider the following matrix:

a. What is the mean value in each column?


b. What is the median for each column?
c. What is the mean value in each row?
d. What is the median for each row?
e. What is returned when you request the mode?
f. What is the mean for the entire matrix?
14) Consider the following matrix:

a. Sort matrix x.
b. Sort matrix x in descending order.
c. Sort the rows in matrix x.
d. Sort rows in matrix x based on the values in column 3.
15) Consider the following matrix:

a. What is the mean value in each column?


b. What is the median for each column?
c. What is the mean value in each row?
d. What is the median for each row?
e. What is returned when you request the mode?
f. What is the mean for the entire matrix?

16) Consider the following matrix:

a. Use the size function to determine the number of rows and columns in this matrix.
b. Use the sort function to sort each column in ascending order.

3
Computer Applications

c. Use the sort function to sort each column in descending order.


d. Use the sortrows function to sort the matrix so that the first column is in ascending order,
but each row still retains its original data.
17) Do the following:
a. Create a 3 x 3 matrix of evenly distributed random numbers.
b. Create a 3 x 3 matrix of normally distributed random numbers.
c. Create a 100 x 5 matrix of evenly distributed random numbers.
d. Find the maximum, the standard deviation, the variance, and the mean for each column in
the matrix that you created in Exercise 3.
e. Create a 100 x 5 matrix of normally distributed random numbers. Be sure to suppress the
output.
f. Find the maximum, the standard deviation, the variance, and the mean for each column in
the matrix you created in Exercise 5.
g. Explain why your results for Exercises 4 and 6 are different.

18) Do the following:


a. Create the following complex numbers:
1. A = 1 + i
2. B = 2 — 3i
3. C = 8 + 2i
b. Create a vector D of complex numbers whose real components are 2, 4, and 6 and whose
imaginary components are -3, 8, and -16.
c. Find the magnitude (absolute value) of each of the vectors you created in Exercises 1 and
2.
d. Find the angle from the horizontal of each of the complex numbers you created in Exercises
1 and 2.
e. Find the complex conjugate of vector D.
f. Use the transpose operator to find the complex conjugate of vector D.
g. Multiply A by its complex conjugate, and then take the square root of your answer. How
does this value compare against the magnitude (absolute value) of A?

4
Sheet Chapter (1)

19) The following table gives the hourly loading of a certain distribution feeder:
hr 1 2 3 4 5 6 7 8 9 10 11 12
Kw 1370 1120 1050 980 980 1075 1230 1450 1509 1520 1640 1750
KVAr 550 530 500 460 500 520 520 650 540 605 700 720
hr 13 14 15 16 17 18 19 20 21 22 23 24
Kw 1720 1740 1680 1530 1630 1760 1850 2020 1980 1720 1660 1580
KVAr 715 685 695 590 635 750 780 800 820 715 650 600

Write script M-file (all in one M-file) to read the measured active and reactive powers then
complete the MATLAB code to do the following;
a. Calculate the feeder loading in VA for each hour and draw the loading curve with respect
to daily hours.
b. Find the maximum loading value and the corresponding hour.
c. Find the average (mean) daily loading.
d. Draw the power factor at the supplying point with time and find the worst and best power
factor and the corresponding hour.
e. Find the circuit breaker ratting current (where the circuit breaker or fuse protection
device is designed to withstand the maximum loading current with a safety factor 125%).
The system voltage is assumed to be constant at 380 volt, 50Hz as a line voltage.
f. At what hour the feeder if heavily loaded.
g. Draw the voltage and current sinewave at hour 7 on the same figure to show the phase
shift between voltage and current as well as other technical information.
h. Draw the needed injected or absorbed reactive power to maintain system power factor at
0.95 lagging.
i. Design a matrix including all system data corresponding to daily hours. The data needed
are system KW, KVAr, I, P.F and S (VA).
j. Sort the previous matrix in ascending order with respect to the feeder current.
k. Find the number of column, rows and the length of the previous matrix.
l. If the supply voltage fluctuates around the nominal value (380V) with a maximum
variation of ±5%. Suppose a random supply voltage within the specified range for each
daily hour. Then design another matrix similar to that in “i”.

You might also like