控制系统仿真(MATLAB)实验2
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
MATLAB实验二
自动化2班解洪超200940600138
一、实验目的:
1. Learn to design branch and loop statements program
2. Be familiar with relational and logical operators
3. Practice 2D plotting
二、实验内容:
1. Assume that a,b,c, and d are defined, and evaluate the following expression.
a=20; b=-2; c=0; d=1;
(1) a>b; ans= 1(2) b>d; ans= 0
(3) a>b&c>d; ans=0
(4) a==b; ans= 0 (5) a&b>c; ans=0
6) ~~b; ans=1
a=2; b=[1 –2;-0 10]; c=[0 1;2 0]; d=[-2 1 2;0 1 0];
(7) ~(a>b)
ans =
0 0
0 1
(8) a>c&b>c
ans =
1 0
0 1
(9) c<=d
Error using ==> le
Matrix dimensions must agree.
a=2; b=3; c=10; d=0;
(10) a*b^2>a*c ans= 0 (11) d|b>a
ans= 1 (12) (d|b)>a ans= 0
a=20; b=-2; c=0; d=’Test’;
(13) isinf(a/b) ans=014) isinf(a/c)
ans=1(15) a>b&ischar(d)ans=1(16)
isempty(c) ans= 0
2. Write a Matlab program to solve the
function1
()ln
1
y x
x
=
-
, where x is a number <1. Use an if structure to verify
that the value passed to the program is
legal. If the value of x is legal, caculate
y(x). If not ,write a suitable error
message and quit.
x=input('enter a number of x:')
if x<1
y=log(1/(1-x))
else
disp('the value of x is illegal.')
end
enter a number of x:0.5
y =
0.6931
enter a number of x:3
the value of x is illegal.
3. Write out m. file and plot the figures with grids
Assume that the complex function f(t) is defined by the equation
f(t)=(0.5-0.25i)t-1.0
Plot the amplitude and phase of function for 0 4.
t
≤≤
t=0:0.001:4;
m=sqrt((0.25.*t).^2+(0.5.*t-1).^2)
n=atan((0.25.*t)./(0.5.*t-1))
plot(t,m,'k-',t,n)
grid on
1
4. Write the Matlab statements required to calculate y(t) from the equation
22350
()350t t y t t t -+≥⎧=⎨
+<⎩
for value of t between –9 and 9 in steps of 0.5. Use loops and branches to perform this calculation. for t=-9:0.5:9 if t<0
y=3*t^2+5 else
y=-3*t^2+5 end end
y =248 y =221.7500 y = 197 y = 173.7500 y =152y =131.7500 y =113 y = 95.7500 y =80 y = 65.7500 y =53 y = 41.7500 y =32 y =23.7500 y =17 y =11.7500 y =8 y =5.7500 y =5 y =4.2500 y =2 y =-1.7500 y =-7 y =-13.7500
y=-22
y
=-31.7500
y=-43y=-55.7500 y=-70 y=-85.7500 y=-103 y=-121.7500 y =-142
y =-163.7500 y =-187 y = -211.7500 y =-238
5. Write an m.file to evalue the equation
2()32y x x x =-+for all values of x
between 0.1 and 3, in steps of 0.1. Do
this twice, once with a for loop and once with vectors. Plot the resulting function using a 4.0 thick dashed blue line.
for x=0.1:0.1:3 y=x^2-3*x+2; plot(x,y,'bo--'); hold on; end
x=0.1:0.1:3; y=x.^2-3*x+2;
plot(x,y,'b--','LineWidth',4.0) grid on