matlab实验

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
legend('f(x)','d/dx f(x)');grid on;
3.Edit & Run the m-file
% testsubplotandloglogfunction
x=0:0.1:10;y=x.^2-10.*x+26;
subplot(2,2,1);plot(x,y);grid on;
subplot(2,2,2);semilogx(x,y);grid on;
>> f=(1/2)^x;
>> fx=limit(f,x,inf)
fx =
0
例3
X>0时
>> syms x
>> f=(((1+x)^(1/x))/(exp(1)))^(1/x);
>> fx=limit(f,x,0,'right')
fx =
0
X<0时
>> exp(-1/2)
ans =
1.6065
例4
>> syms x
x=-pi:pi/20:pi;y=sin(x);plot(x,y);grid on;
title('Subplot 1 Title');
subplot(2,1,2);
x=-pi:pi/20:pi;y=cos(x);plot(x,y);grid on;
title('Subplot 2 Title');
3.Polar Plotsexercise
(10)a*b^2>a*c(11)d|b>a(12)(d|b)>a
a=20; b=-2; c=0; d=’Test’;
(13)isinf(a/b)(14)isinf(a/c)(15)a>b&ischar(d)(16)isempty(c)
5.Writea Matlab program to solve the function ,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.
amps=volts./(rs+rl);pl=(amps.^2).*rl;[maxvol,index]=max(pl);
plot(rl,pl,rl(index),pl(index),'rh');grid on;
PART II:(选择练习,不需提交实验报告)
1.Hold command exercise
Plot the amplitude and phase of function for
t=0:0.01:4;
f=(0.5-0.25*i)*t-1.0;
figure(1);
plot(t,abs(f));
title('amplitude response');
figure(2);
plot(t,angle(f));
y =
exp(atan(1/x))
>> diff(y)
ans =
-1/x^2/(1+1/x^2)*exp(atan(1/x))
>> diff(y,2)
ans =
2/x^3/(1+1/x^2)*exp(atan(1/x))-2/x^5/(1+1/x^2)^2*exp(atan(1/x))+1/x^4/(1+1/x^2)^2*exp(atan(1/x))
>> fx2=diff(dydx,x)
fx2 =
(2/(x^2+y^2)^2*x^2-1/(x^2+y^2)+2*y/x^3/(1+y^2/x^2)-2*y^3/x^5/(1+y^2/x^2)^2)/(1/(x^2+y^2)*y-1/x/(1+y^2/x^2))-(-1/(x^2+y^2)*x-y/x^2/(1+y^2/x^2))/(1/(x^2+y^2)*y-1/x/(1+y^2/x^2))^2*(-2/(x^2+y^2)^2*y*x+1/x^2/(1+y^2/x^2)-2/x^4/(1+y^2/x^2)^2*y^2)
PART I:下列选择练习,不需提交实验报告
1.Edit & Run the m-file
% test stepresponsefunction
wn=6;kosi=[0.1:0.1:1.0 2];
figure(1);hold on
for kos=kosi
num=wn^2;den=[1,2*kos*wn,wn.^2];step(num,den)
PART III: (需提交实验报告)
1.
3.Write outm. file and plot the figureswith grids
Assume that the complex function f(t) is defined by the equation
f(t)=(0.5-0.25i)t-1.0
g=0.5;
theta=0:pi/20:2*pi;
gain=2*g*(1+cos(theta));
polar(theta,gain,'r-');
title('\fontsize{20} \bfGain versus angle \theta');
4.Assume that a,b,c, and d are defined, and evaluate the following expression.
x=-pi:pi/20:pi;
y1=sin(x);y2=cos(x);plot(x,y1, 'b-');hold on;
plot(x,y2, 'k--');hold off;
legend ('sinx', 'cosx')
2.Figure command exercise
figure(1);
subplot(2,1,1);
(1)
>> syms x
>> y=log(sin((x^2+1)^(1/2)));
>> diff(y)
ans =
cos((1+x^2)^(1/2))/(1+x^2)^(1/2)*x/sin((1+x^2)^(1/2))
>> subs(diff(y),x,0)
ans =
0
(2)
>> syms x
>> y=exp(atan(1/x))
title('phase response');
4. Writethe Matlab statements required to calculate y(t) from the equation
for value of t between –9 and9 insteps of 0.5. Use loops and branches to perform this calculation.
ans =
1.1000 0
0 1.1000
2.1000 0.1000
-1.4000 5.1000
4)What is the size and value of array1([1 3], end)?2 1
ans =
6.0000
1.3000
2.Give the answer of the following commad
4)4) array1([1 1],:)
ans =
1.1000 0 2.1000 -3.5000 6.0000
1.1000 0 2.1000 -3.5000 6.0000
4.Give the answer of the following operations
1)a+b
ans =
3 -3
-1 4
2)a*d
y=exp(1/(x-1))
limit(y,x,0,'right')
ezplot(y,[0,pi])
y =
exp(1/(x-1))
ans =
exp(-1)
>> syms x
y=log(1+x)
limit(y,x,0,'left')
ezplot(y,[-1,0])
y =
log(1+x)
ans =
0
练习1
ans =
1
练习1
(2)
>> limit(sin(x)/x,x,0)
ans =
1
练习1
(3)
>> limit((1+1/x)^x,x,inf)
ans =
exp(1)
练习1
(4)
>> limit((1-cos(x))/((exp(x)-1)*log(1+x)),x,0)
ans =
1/2
练习1
(5)
>> limit(log(sin(x))/(pi-2*x)^2,x,pi/2)
a=20; b=-2; c=0; d=1;
(1)a>b;(2)b>d;(3)a>b&c>d;(4)a==b;(5)a&b>c;6)~~b;
a=2; b=[1 –2;-0 10]; c=[0 1;2 0]; d=[-2 1 2;0 1 0];
(7)~(a>b)(8)a>c&b>c(9)c<=d
a=2; b=3; c=10; d=0;
1.Give the answer of the following questions for the array
1)What is the size of array1?4 5
2)What is the value of array1(4,1)?-1.4
3)What is the size and value of array1(:,1:2)?4 2
1) a=1:2:5;1 3 5
2) b=[a’a’a’];
b =
1 1 1
3 3 3
5 5 5
3) c=b(1:2:3,1:2:3);
c =
1 1
5 5
4) d=a+b(2,:)
d =
4 6 8
5) w=[zeros(1,3)ones(3,1)’3:5’]
w =
0 0 0 1 1 1 3 4 5
3.Give the answer of the sub-arrays
end
hold off;
2.Edit & Run the m-file
% test plot function
x=0:pi/20:3*pi;y1=sin(x);y2=2*cos(2*x);plot(x,y1,'rv:',x,y2,'bo--');
title('Plot the Line of y=sin(2x) and its derivative');xlabel('X axis');ylabel('Y axis');
counter=1;
for(i=-9:0.5:9)
if i<0
data(counter)=3*i^2+5;
else
data(counter)=-3*i^2+5;
end
counter=counter+1;
end
i=-9:0.5:9;
plot(i,data);
Result:
练习1
(1)
>> limit((n)^(1/n),n,inf)
subplot(2,2,3);semilogy(x,y);grid on;
subplot(2,2,4);loglog(x,y);grid on;
4.Edit & Run the m-file
% test mΒιβλιοθήκη Baidux and plot function
volts=120;rs=50;rl=1:0.1:100;
(3)
>> syms x y
>> f=log(sqrt(x^2+y^2))-atan(y/x);
>> fx=diff(f,x);
>> fy=diff(f,y);
>> dydx=-fx/fy
dydx =
(-1/(x^2+y^2)*x-y/x^2/(1+y^2/x^2))/(1/(x^2+y^2)*y-1/x/(1+y^2/x^2))
ans =
2 -2
-1 2
3)a.*d
ans =
2 0
0 2
4)a*c
ans =
6
-5
5)a.*c ERROR
6)a\b
ans =
1.0000 1.0000
0.5000 1.5000
7)a.\b
ans =
0.5000 0.5000
0 1.0000
8)a.^b
ans =
2.0000 -0.5000
1.0000 4.0000
1)array1(3,:);
ans =
2.1000 0.1000 0.3000 -0.4000 1.3000
2)2) array1(:,3);
ans =
2.1000
-6.6000
0.3000
0
3)3) array1(1:2:3,[3 3 4])
ans =
2.1000 2.1000 -3.5000
0.3000 0.3000 -0.4000
ans =
-1/8
例2
(1)
>> syms x
>> y=(1/2)^x;
>> ezplot(y)
(2)
>> syms x
>> f=(1/2)^x;
>> fx=limit(f,x,inf)
fx =
0
>> syms x
>> f=(1/2)^x;
>> fx=limit(f,x,-inf)
fx =
inf
>> syms x
相关文档
最新文档