You are on page 1of 2

CEL331 STRUCTURAL ANALYSIS II (2012-13

)
DEPARTMENT OF CIVIL ENGINEERING
IIT DELHI 

MATLAB EXERCISE
(Available online at: http://web.iitd.ac.in/~sbhalla/cel331.htm)

1. Run MATLAB
2. Set working directory as DESKTOP using path browser.
3. Create a matrix A by typing A = [23, 45, 63] and another matrix B by B = [27,05,-13].
4. Produce C = A+B.
5. Multiply each element of C by 5.
6. How will you create a matrix of size m x n? Use the help menu of MATLAB. Also learn basic
matrix operations.
7. Create a text file containing numbers from 1 to 20, one on each line.
8. Read this file into a matrix “x” using MATLAB. To see syntax, type: “help dlmread” in the
command prompt.
9. Create another matrix “y” with each element equal to the square of each element of “x”. (HINT: use
for loop, you may type “help for” to see syntax)
10. Plot (x,y) {type “help plot” to see the syntax}
11. Save the plot, copy and paste it on word.
12. Save the matrix “y” on a text file (type: “help dlmwrite” for syntax).
13. Create a text file containing a 7x4 matrix, with all elements separated by “tab”. Import the matrix
“M” in MATLAB using “dlmread” command.
14. Learn how to transfer a matrix from MATLAB to EXCEL and vice versa.
15. Import first five elements of first two columns of the matrix “M” into variables “x” and “y”. Obtain
a plot of “x” vs “y”.
16. Create a set of numbers from 1 to 100 in a matrix A by : A = (1:100).
1 | P a g e


2 | P a g e

17. Write a program to plot f(t) = e
-at
sinωt, where the values of A and ω are provided by the user.
Choose a = 0.001 and ω = 3 and display the plot.
18. Learn the use of commands “ls” and “clear”.
19. Write a program in a separate file (abc.m) to obtain the derivative of function f(x) = 2x
2
+ 5x+3 at x
= 10.Compare the result with exact value. Can you directly determine the derivative using functions
already available in MATLAB?
20. Repeat exercise 19 by replacing differentiation by integration in range (x=10 to 20). Also use the
built-in functions of MATLAB.