You are on page 1of 6

MATLAB Programming for

Engineers
姓名:户桂民
学号:06030229
班级:0290601

日期:2008/05/11

One:objectives

1.Help the students to became more familiar with branching statements.


2.Put what the students have learned into practice.

Two :contents

3.1 Conmand lines and results:

% This is program evaluate tan()


theta=input('Please input the \theta in degrees:');
if abs(cos(theta))>= 1.0e-20
m=sin(theta)/cos(theta);
fprintf('tan(theta)=%8.5f\n',m);
else
fprintf('Error message input!');
end

>> Please input the theta in degrees:3


tan(theta)=-0.14255

3.2 .Conmand lines and results:

temp=input('input a number:');
if temp >103.0
disp('Temperature dangerousely high');
elseif temp >99.5
disp('Temperature slightly high');
elseif temp >=97.5
disp('Temperature normal');
else
disp('Temperature below normal');
end

2
>> hu2
input a number:3
Temperature below normal
>> hu2
input a number:100
Temperature slightly high

3.3 Conmand lines and results:

temp= input('input the weight of the package in pounds:');


if temp>100
frintf('Can;t accepted(太重了)');
elseif temp>70
money=10+68*3.75+10;
fprintf('Cost:%4.2f dollars',money);
elseif temp>2
money=10+(temp-2)*3.75;
fprintf('Cost:%4.2f dollars',money);
else
fprintf('Cost:10 dollars');
end

>> hu3
input the weight of the package in pounds:100
Cost:275.00 dollars
>> hu3
input the weight of the package in pounds:50
Cost:190.00 dollars

3.4 Conmand lines and results:

x=input('input x:');
y=input('input y:');
if x>=0
if y>=0
funxy=x+y;
else
funxy=x+y^2;
end
else
if y>=0
funxy=x^2+y;
else

3
funxy=x^2+y^2;
end
end
fprintf('f(x,y)=%10.2f',funxy);

>> hu4
input x:5
input y:6
f(x,y)= 11.00

3.5Conmand lines and results:

x=input('input x(x<1):');
if x<1
y=log(1/(1-x));
fprintf('y(%f)=%f',x,y);
else
fprintf('Error input')
end

>> hu5
input x(x<1):0.2
y(0.200000)=0.223144

3.11 Conmand lines and results:

r=16000;
c=1.0e-6;
subplot(2,1,1);
f=1:2:1000;
v_oi=abs(j*2*pi*r*c*f./(1+j*2*pi*f*r*c));
loglog(f,v_oi);
title('Amplitude response');
xlabel('frequence(HZ)');
ylabel('Ouput/Input ratio');
grid on
subplot(2,1,2);
ff=1:2:1000;
phase_oi=angle(j*2*pi*r*c*ff./(1+j*2*pi*ff*r*c));
semilogx(ff,phase_oi);
title('Phase response');

4
xlabel('frequence(HZ)');
ylabel('Ouput-Input phase(rad)');
grid on

3.12.Conmand lines and results:

k=0.5
theta=0:0.1:6*pi;
r=k.*theta;
x=r.*cos(theta);
y=r.*sin(theta);
plot(x,y);
grid on
xlabel('X');
ylabel('Y');
title('The Spiral of Archimedes');

5
Three: Experience

We must use MATLAB regularity.


Because we may forget something if we don’t use it for a long time.

You might also like