Uploaded by 蔡明穎

function my

advertisement
1.
function my_circle(r,x0,y0)
%畫一個圓
t=linspace(0,2*pi,180);
x=r*cos(t)+x0;
y=r*sin(t)+y0;
plot(x,y,'b');axis equal
hold on
2.
function circlemat(n)
%µen*n-Ó¶ê
for a=1:n;
for b=1:n;
my_circle(1,2*(a-1),2*(b-1));
end
end
box off
3.
function normdistribution(mu,sig)
%常態分佈取縣
x=linspace(mu-2*sig,mu+2*sig,100);
plot(x,(1/(sqrt(2*pi)*sig))*exp(-(x-mu).^2/(2*sig^2)));
xlabel('x');ylabel('y');title('normal distribution')
4.
function poop(p,q)
%可以畫便便
t=linspace(0,p,q);
plot3((30-t).*sin(t),(30-t).*cos(t),t,'-m',(30-t).*sin(
t),(30-t).*cos(t),-t,'--g')
5.
function Primeprod(n,opt)
if opt==1
m=primes(n);
sum(m)
else
opt==2;
m=primes(n);
prod(m)
end
6.
unction Primeprod_v2(n,opt)
if opt==1
%¿ï¾Ü1:§â¨ìn¤§«eªº½è¼Æ¥þ³¡¬Û¥[
m=primes(n);
fprintf('%d+',m)
tot=sum(m);
fprintf('\b=%d\n',tot)
else
opt==2;
%¿ï¾Ü2:§â¨ìn¤§«eªº½è¼Æ¥þ³¡¬Û-¼
m=primes(n);
fprintf('%d*',m)
k=prod(m);
fprintf('\b=%d\n',k)
end
7.
function quadsolver(a,b)
%¥i¥H¸Ñ¯x°
x=inv(a)*b
8.
function sumprimes(n)
tot=0;
%把n之前的植樹全部相加
for m=2:n;
if isprime(m);
tot=tot+m;
fprintf('%d+',m)
end
end
fprintf('\b=%d\n',tot)
Download