Home, Matlab exercise 1, Matlab exercise 2, Matlab exercise 3.
Arithmetic:
>> 7+9
>> 3*2
>> 2(3+4)
>> 2+3*4
>> (2+3)*4
>> 2^3
>> 21/7
>> ans*2
>> 3,14
>> 3.14
>> pi
>> 2/3
>> format long
>> 2/3
>> pi
>> round(ans)
>> ceil(3.1)
>> floor(3.1)
>> help
>> help ops
>> helpwin
>> helpdesk
Exercises:
1. Compute the sum of the product of 3 and 4 and the difference
between 9 and 3.
2. Convert the binary numbers 10010000 and 1111111111 to the
decimal form. Hint: use 2^j.
3. Use helpwin or helpdesk to find a matlab command that does the
conversion in previous exercise. Hint: search for binary.
4. Express pi rounded to 3 decimals. Hint: round 1000*pi.
=================
Variables:
>> a=3
>> b=5; (What is the effect of ; here?)
>> b
>> c=a+2*b;
>> c=c+1
>> c=a*d;
>> base=3
>> height=5
>> area=base*height/2
>> a_minus_b=a-b
>> who
>> whos
>> help who
>> help whos
>> clear
>> who
==================
Vectors/lists:
>> v=[4 1 7 5]
>> v(3)
>> v(3)=8
>> v(5)
>> w=[1 2 3 4]
>> v+w
>> v-w
>> v+1
>> 2*w
>> w/4
>> sum(w)
>> v*w
>> v.*w
>> w.^2
>> [v w]
>> ans'
>> u=1:4
>> u=0:2:10
>> u=0:3:9
>> u=0:3:10
>> u=0:.2:.6
>> u(2:3)
>> help linspace
>> linspace(0,1,6)
Exercises:
1. Define a price list for magazines, movie, cd, and a corresponding
list of how many of these items you consume during a year. Then use
these lists to compute a list of the total cost for each of the three
items and the total cost.
2. Test whether
1+2+3+..+N ~= N^2/2 and 1+2^2+3^2+..+N^2 ~= N^3/3. Hint:
first define x=1:N and use sum. What does ~= mean?
======================
Matrices:
>> m=[1 2 3; 4 5 6]
>> m(2,1)
>> m(1,3)
>> m(1,3)=7
>> v
>> w
>> [v;w]
>> v'
>> ans(3)
>> w'
>> [v' w']
>> ans'
>> [v';w']
>> who
>> help save
>> save junk
>> clear
>> who
>> load junk
>> who
>> quit