当前位置:文档之家› matlab实验

matlab实验

(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.
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)
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
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
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
>> 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
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
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);
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 max and plot function
volts=120;rs=50;rl=1:0.1:100;
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
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
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));
(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))
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;
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
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)
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');
y=exp(1/(x-1))
limit(y,x,0,'right')
ezplot(y,[0,pi])
y =
exp(1/(x-1))
相关主题