Sei sulla pagina 1di 3

MTC014 Fundamentals of Structural Analysis

MATLAB exercises
1. Start MATLAB. Type x = -1:0.2:1 to create an x-axis vector. Then execute the
following statements and examine the effects.
sqrt(x)
sin(x)
cos(x)
x.^2
x.^3
plot(x, x.^2)
plot(x,sqrt(x))
2. Examine what happens when you execute the following statements:
x = [1 2 3 4]
y = -2:2:4
x.^y
x.*y
x./y
x*y
x*y
x*y
3. Make a matrix by typing M = rand(4)
Find the inverse of M, using the function inv.
Multiply the inverse and M together and watch the result!
4. Make a matrix by typing M = randn(5)
Examine
M(:,3)
M(1:2,4)
M(3,:)
M(3,4)
M(4,3:4)
diag(M)
sum(M)
5. Solve the following system of linear equations using inv, \ and /
3x + 2y + z = 2
5x y z = 6
x+y+z = 0

MTC014 Fundamentals of Structural Analysis


6. Write a MATLAB script to produce graphs of y = cos(x) and y = cos(x3) in the range x
= -4:0.02:4 using the same axes. Use xlabel, ylabel and title. Also try legend and
different FontSize.
7. An iterative equation for solving the equation x2 x -1 = 0 is given by
xr+1 = 1 + 1/xr for r = 0, 1, 2, 3,
Given x0 is 3 write a MATLAB script to solve the equation. A satisfactory result is
when two successive iterations differ with less than 0.0001.
8. Write a MATLAB function to solve the equation
ax2 + bx + c = 0
The output shall be the two roots, and the input shall be a, b, c.
9. Create a time vector t from zero to two seconds using a time step of 10 milliseconds.
Then create a sine with amplitude 2.3 and frequency 7 Hz using your time vector. Plot
the result and label the graph!
10. Print the graph in exercise 9 to a file in different formats, bitmap, jpeg,
Then import the file to a Word document and observe the differences!
11. Create a color plot with
surf(peaks);shading interp
Print it in different formats and import the result to Word.
12. Write a script that makes a series of graphic files. Use a for-loop to produce plots of
sine-waves with frequencies 1, 2, 3, 4, , 9, 10 Hz. Use a time axis from zero to 2
seconds. Make nice plots using xlabel, ylabel, title and axis. Use eval within the loop
to print graphic files with names like figure1.jpg, figure2.jpg, etc.

MTC014 Fundamentals of Structural Analysis


13. Write a script that finds the first five roots to the equation 1 + cos( x ) cosh( x ) = 0 .
Use the fzero function in MATLAB. The equation appears when we handle the
properties of a cantilever beam.
3

14. Write a script that solves the equation 1 + x = 0 with Newtons iterative method. If
the equation to solve is f ( x ) = 0 , and the nth estimate of a root is xn, then the next
estimate x n +1 = x n

f ( xn )
.
f ( x n )

Start at an arbitrary point in the complex plane and study where the procedure ends.
Then make a script that covers the whole area abs(real(x))<1 and abs(imag(x))<1 with
starting points. Color the starting points differently according to where the iteration
ends. Then limit the starting points to interesting intervals.
15. A sine function may be expressed as f ( x ) = a cos( x ) + b sin( x ) . Generate a vector x
and then f(x) with some a and b. Now, with x and f(x) given, write a script that
identifies a and b using some least square estimate. A least square estimate minimizes
the error between the given function and the solution.
16. Study some useful MATLAB functions by making simple examples. Study for
instance:
clock
date
now
datestr
datetick
tic and toc

17. Study the text function. Write a simple script where you plot a function and plot the
text maximum is = and then the maximum value. The text should automatically be
placed near the maximum of the function in the plot.

Potrebbero piacerti anche