内容发布更新时间 : 2024/12/24 10:42:52星期一 下面是文章的全部内容请认真阅读。
Matlab Worksheet 1
Part A
1. Get into Matlab: Use the diary command to record your activity in to a file: diary mydiary01.doc before you start your work. (And diary off to switch off your diary when you finish your work.)
At the Command Window assign a value x=10, then use the Up Key ↑ to repeat the expression, editing it to show the effect of using a semicolon after the 10, namely x=10; Answers: >> x=10 x = 10
>> x=10;
2. Confirm whether the following names of variables are acceptable:
a) Velocity Yes No b) Velocity1 Yes No c) Velocity.1 Yes No d) Velocity_1 Yes No e) Velocity-01 Yes No f) velocityONE Yes No g) 1velocity Yes No
3. Assign two scalar variables x and y values x=1.5, y=2.3, then construct Matlab expressions for the following:
5x3ya) z?
x?y b) z?x?7y?2/3???2yx1/6 c) z???1??e 5logx?1?10???d) z?sin(2?x?y)?excos(2?x) Answers:
>> x=1.5;y=2.3 z1=5*x^3*y/(x+y) z2=(x^7*y^0.5)^(2/3)
z3=(x^(1/6)/(log10(x^5-1))+1)*exp(-2*y) z4=sin(2*pi*x-y)+exp(x).*cos(2*pi*x) z1 = 10.2138 z2 = 8.7566 z3 = 0.0232 z4 = -3.7360
4. Assign two variables with complex values u=2+3j and v=4+10j and then construct expression for:
uu?j2?ua) b) uv?2j c) d) ve
v2jAnswers:
>> u=2+3j;v=4+10j; z1=u/v z2=u*v+2j z3=u/2j
z4=v*exp(-j*2*pi*u) z1 =
0.3276 - 0.0690i z2 =
-22.0000 +34.0000i
z3 =
1.5000 - 1.0000i z4 =
6.1421e+08 + 1.5355e+09i
5. Use the colon operator : to assign numerical values between 0 and 1 to vector array variable a in steps of 0.1.
Answer:
>> V=0:0.1:1 V =
Columns 1 through 10
0 0.1000 0.2000 0.3000 0.4000 0.5000 0.6000 0.7000 0.8000
0.9000
Column 11
1.0000
6. Use linspace function to assign 20 values to vector variable y between 20 and 30.
Answer:
>> V=linspace(20,30,20) V =
Columns 1 through 10
20.0000 20.5263 21.0526 21.5789 22.1053 22.6316 23.1579 23.6842 24.2105 24.7368
Columns 11 through 20
25.2632 25.7895 26.3158 26.8421 27.3684 27.8947 28.4211 28.9474