资源描述
1. a1.m:
function y=a1(n)
k=sqrt(n);
flag=1;
for i=2:k;
if mod(n,i)==0
flag=0;
break
end
end
f=flag;
if f==1
disp('该数是素数')
else
disp('该数不是素数')
end
a11.m:
n=input('Please input n:')
a1(n)
3.c1.m:
function y=c1(x)
y=0;
n=fix(log10(x))+1;
for i=1:n
y=y+~mod(x,10);
x=fix(x/10);
end
c11.m:
s=0;
for i=1:2006
s=s+c1(i);
end
s
5.d1.m:
function y=d1(step,linestyle)
y=0;
x1=-3:step:-1-step;
x2=-1:step:1-step;
x3=1:step:3;
y1=(-x1.^2-4*x1-3)/2;
y2=-x2.^2+1;
y3=(-x3.^2+4*x3-3)/2;
x=[x1,x2,x3];
yy=[y1,y2,y3];
plot(x,yy,linestyle)
d11.m:
y=d1(0.01,'r-')
6.e1.m:
function y=e1(x)
ch=menu('Ñ¡Ôñ¾ØÕó','[-10,10]¾ùÔÈ·Ö²¼','[-5,5]¾ùÔÈ·Ö²¼','[-1,1]¾ùÔÈ·Ö²¼','(0,1)Õý̬·Ö²¼');
switch ch
case 1,y=10-20*rand(x);
case 2,y=-5-10*rand(x);
case 3,y=-1-2*rand(x);
case 4,y=randn(x);
end
e11.m:
x=input('Please input x:')
e1(x)
7. a=input('ÇëÒÀ´ÎÊäÈëÓïÑÔ£¬Êýѧ£¬Ó¢ÓÎïÀí£¬»¯Ñ§£¬ÉúÎï³É¼¨£»Èç:[68 72 65 68 35 79]:');
w=[2 3 2 4 2.5 1];
sum=0;w1=0;
for e=1:6
w1=w1+w(e);
end
for j=1:6
sum=sum+a(j).*w(j);
end
y=sum./w1;
disp(y)
8. function y=fun408()
I=input('请输入利润I:');
if(I<=10)
n=0;
else
if(10<I&I<=20)
n=1;
else
if(20<I&I<=40)
n=2;
else
n=3;
end
end
end
switch n
case 0,K=I*0.1;
case 1,K=10*0.1+(I-10)*0.05;
case 2,K=10*0.1+10*0.05+(I-20)*0.02;
case 3,K=10*0.1+10*0.05+20*0.02+(I-40)*0.01;
end
y=K;
9. function y=fun()
n=input('请输入项数n:');
value=0;
a(1)=2;
b(1)=1;
a(2)=3;
b(2)=2;
sum(1)=a(1)./b(1);
sum(2)=a(2)./b(2);
for i=3:n
a(i)=a(i-2)+a(i-1);
b(i)=b(i-2)+b(i-1);
sum(i)=a(i)./b(i);
end
for j=1:n
value=value+sum(j);
end
y=value;
10. function y=shaixuan(a,b)
a=input('a=');
b=input('b=');
n=a;
x=[1:n];
i=0;
m=0;
j=1;
while(n>0)
i=i+1;
m=m+1;
if(m==b)
k(j)=x(i);
j=j+1;
n=n-1;
for(v=i:n) x(v)=x(v+1);
end
m=0;
i=i-1;
end
if(i==n)
i=0;
end
end
y=k
展开阅读全文