database

코딩특강

작성자
cfdkim
작성일
2023-05-12 09:41
조회
288
clear
n=10;
maxit=10000;
for k=1:n-1
for m=1:maxit
x=randperm(n);
y(m)=x(n);
for i=k+1:n-1
if x(i)<min(x(1:k))
y(m)=x(i);
break
end
end
if y(m)>1.5
y(m)=0;
end
end
z(k)=sum(y);
end
plot(z)
number=find(z==max(z))
ratio=max(z)/maxit
전체 7

  • 2023-05-31 23:37

    clear; clf; hold on
    n=36;
    t=linspace(0,4*pi,2*n+1);
    x=cos(t);
    y=sin(t);
    plot(x,y,'o');
    axis image
    axis off
    s=7;
    for i=1:n
    plot([x(i) x(i+s)],[y(i) y(i+s)])
    pause(0.1)
    end


  • 2023-05-12 16:29

    clear; clf; hold
    S(1)=100; r=0.021; volatility=0.2;
    T=1; N=365; dt=T/N; t=linspace(0,T,N+1);
    for k=1:70
    Z=randn(1,N);
    for i=1:N
    S(i+1)=S(i)*exp((r-1/2*volatility^2)*dt...
    +volatility*Z(i)*sqrt(dt));
    end
    plot(t,S);
    end
    xlabel('Time'); ylabel('Stock Process');


  • 2023-05-12 17:33

    clear; clf; hold on
    N=20;
    tN=25*N;
    theta=linspace(10*pi, 0, tN+1);
    x=cos(theta);
    y=sin(theta);
    plot(x,y,'ko'); axis image off;
    a=0.9;
    for k=1:2.5*N+1
    plot([x(k) a*x(2*k)+(1-a)*x(2*k+1)],[y(k) a*y(2*k)+(1-a)*y(2*k+1)],'g')
    plot([x(k) a*x(2*k)+(1-a)*x(2*k-1)],[y(k) a*y(2*k)+(1-a)*y(2*k-1)],'g')
    end
    for k=1:2.5*N+1
    plot([x(k+N) a*x(2*k+N)+(1-a)*x(2*k+1+N)],[y(k+N) a*y(2*k+N)+(1-a)*y(2*k+1+N)],'r')
    plot([x(k+N) a*x(2*k+N)+(1-a)*x(2*k-1+N)],[y(k+N) a*y(2*k+N)+(1-a)*y(2*k-1+N)],'r')
    end
    for k=1:2.5*N+1
    plot([x(k+2*N) a*x(2*k+2*N)+(1-a)*x(2*k+1+2*N)],[y(k+2*N) a*y(2*k+2*N)+(1-a)*y(2*k+1+2*N)],'c')
    plot([x(k+2*N) a*x(2*k+2*N)+(1-a)*x(2*k-1+2*N)],[y(k+2*N) a*y(2*k+2*N)+(1-a)*y(2*k-1+2*N)],'c')
    end
    for k=1:2.5*N+1
    plot([x(k+3*N) a*x(2*k+3*N)+(1-a)*x(2*k+1+3*N)],[y(k+3*N) a*y(2*k+3*N)+(1-a)*y(2*k+1+3*N)],'b')
    plot([x(k+3*N) a*x(2*k+3*N)+(1-a)*x(2*k-1+3*N)],[y(k+3*N) a*y(2*k+3*N)+(1-a)*y(2*k-1+3*N)],'b')
    end
    for k=1:2.5*N+1
    plot([x(k+4*N) a*x(2*k+4*N)+(1-a)*x(2*k+1+4*N)],[y(k+4*N) a*y(2*k+4*N)+(1-a)*y(2*k+1+4*N)],'m')
    plot([x(k+4*N) a*x(2*k+4*N)+(1-a)*x(2*k-1+4*N)],[y(k+4*N) a*y(2*k+4*N)+(1-a)*y(2*k-1+4*N)],'m')
    pause(0.01)
    end


  • 2023-05-12 17:34

    clear; clf; hold on
    n=500;
    t=linspace(0,7*pi,n);
    xa=0*t;
    ya=0*t;
    za=t;
    xb=t.*cos(t);
    yb=t.*sin(t);
    zb=t+10;
    plot3(xa,ya,za,'k.');
    plot3(xb,yb,zb,'b.');
    axis image
    view(-40,15)
    for i=1:n
    plot3([xa(i) xb(i)],[ya(i) yb(i)], ...
    [za(i) zb(i)],'linewidth',1)
    pause(0.01)
    end


  • 2023-05-12 17:35

    clear; clf; hold on
    n=20;
    t=linspace(0,1,n);
    x=[0 1 1 0 0 1 1 0]-0.5;
    y=[0 0 1 1 0 0 1 1]-0.5;
    z=[0 0 0 0 1 1 1 1]-0.5;
    plot3(x,y,z,'o','linewidth',3);
    axis image; view(120,30)
    pp=[1 2 3 4 5 1 4 8 1 5 6 2 3 4 8 7 2 3 7 6 6 7 8 5];
    qq=[2 3 4 1 1 4 8 5 5 6 2 1 4 8 7 3 3 7 6 2 7 8 5 6];
    rr=[3 4 1 2 4 8 5 1 6 2 1 5 8 7 3 4 7 6 2 3 8 5 6 7];
    for k=1:24
    p=pp(k); q=qq(k); r=rr(k);
    x1=x(p)+(x(q)-x(p))*t;
    y1=y(p)+(y(q)-y(p))*t;
    z1=z(p)+(z(q)-z(p))*t;
    x2=x(q)+(x(r)-x(q))*t;
    y2=y(q)+(y(r)-y(q))*t;
    z2=z(q)+(z(r)-z(q))*t;
    for i=1:n
    plot3([x1(i) x2(i)],[y1(i) y2(i)], [z1(i) z2(i)],'linewidth',1)
    pause(0.02)
    end
    end

    n=27;
    t=linspace(0,1,n);
    x=[0 0.5 0 -0.5 0 0];
    y=[0 0 0.5 0 -0.5 0];
    z=[-0.5 0 0 0 0 0.5];

    plot3(x,y,z,'o','linewidth',3);
    axis image; view(120,30)
    pp=[1 2 3 1 3 4 1 4 5 1 2 5 6 2 3 6 3 4 6 4 5 6 2 5];
    qq=[2 3 1 3 4 1 4 5 1 2 5 1 2 3 6 3 4 6 4 5 6 2 5 6];
    rr=[3 1 2 4 1 3 5 1 4 5 1 2 3 6 2 4 6 3 5 6 4 5 6 2];
    for k=1:length(pp)
    p=pp(k); q=qq(k); r=rr(k);
    x1=x(p)+(x(q)-x(p))*t;
    y1=y(p)+(y(q)-y(p))*t;
    z1=z(p)+(z(q)-z(p))*t;
    x2=x(q)+(x(r)-x(q))*t;
    y2=y(q)+(y(r)-y(q))*t;
    z2=z(q)+(z(r)-z(q))*t;
    for i=1:n
    plot3([x1(i) x2(i)],[y1(i) y2(i)], [z1(i) z2(i)],'k','linewidth',1)
    pause(0.02)
    end
    end
    axis off


  • 2023-05-12 18:45

    figure(1); clf;
    A=imread('bbq2.jpg');
    imshow(A); hold on
    z=size(A);
    [xx,yy]=ginput;
    plot(xx,yy,'ro','MarkerFaceColor','r')
    n=length(xx);
    x=linspace(0,z(2),z(2)+1);
    y=linspace(0,z(1),z(1)+1);
    u=zeros(z(2)+1,z(1)+1);
    for i=1:3:z(2)+1
    for j=1:3:z(1)+1
    for k=1:n
    d(k)=sqrt((x(i)-xx(k))^2+(y(j)-yy(k))^2);
    end
    d=sort(d);
    if d(2)-d(1) < 3;
    plot(i, j,'b*');
    if mod(i+j,100)==2
    pause(0.001)
    end
    end
    end
    end


  • 2023-05-12 18:47

    지도자료

    첨부파일 : bbq2.jpg