Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

TUGAS

TANGGAL 17 MARET 2014


1.
%Orbit planet menggunakan metode Euler-Cromer
npoints=500;
dt= 0.002;
x=1;
y=0;
v_x=0;
v_y=2*pi;
plot(0,0,'oy','MarkerSize',30,'MarkerFaceColor','yellow')
axis([-1 1 -1 1]);
xlabel('x(AU)');
ylabel('y(AU)');
hold on;
for step = 1:npoints-1;
radius=sqrt(x^2+y^2);
v_x_new=v_x-(4*pi^2*x*dt)/(radius^3);
v_y_new=v_y-(4*pi^2*y*dt)/(radius^3);
x_new=x+v_x_new*dt;
y_new=y+v_y_new*dt;
plot(x_new,y_new,'-k');
v_x=v_x_new;
v_y=v_y_new;
x=x_new;
y=y_new;
end;

1
0.8
0.6
0.4

y(AU)

0.2
0
-0.2
-0.4
-0.6
-0.8
-1
-1

-0.8

-0.6

-0.4

-0.2

0
x(AU)

0.2

0.4

0.6

0.8

%orbit planet menggunakan metode Runge_Kutta orde kedus


%npoints=500;
npoints=2500;
dt=0.05;
t=0;
x=1;
y=0;
v_x=0;
v_y=8;
plot(0,0,'oy','MarkerSize',30,'MarkerFaceColor','yellow');
xlabel('x(AU)');
ylabel('y(AU)');
hold on;
for step=1:npoints-1;
radius=sqrt(x^2+y^2);
y_dash=y+0.5*v_y*dt;
v_y_dash=v_y-0.5*(4*pi^2*y*dt)/(radius^3);
y_new=y+v_y_dash*dt;
v_y_new=v_y-(4*pi^2*y_dash*dt)/(radius^3);
x_dash=x+0.5*v_x*dt;
v_x_dash=v_x-0.5*(4*pi^2*x*dt)/(radius^3);
x_new=x+v_x_dash*dt;
v_x_new=v_x-(4*pi^2*x_dash*dt)/(radius^3);
plot(x_new,y_new,'-k');
drawnow;
v_x=v_x_new;
v_y=v_y_new;
x=x_new;
y=y_new;
end

2
1.5
1

y(AU)

0.5
0
-0.5
-1
-1.5
-2
-3

-2.5

-2

-1.5

-1

-0.5
x(AU)

0.5

1.5

2.
Mengetik pada function m-file:
function [x_new,y_new]=Orbit_Planet (dt,npoints,v_y)
x=1;
y=0;
v_x=0;
plot(0,0,'oy','MarkerSize',30,'MarkerFaceColor','yellow')
axis([-1 1 -1 1]);
xlabel('x(AU)');
ylabel('y(AU)');
hold on;
for step = 1:npoints-1;
radius=sqrt(x^2+y^2);
v_x_new=v_x-(4*pi^2*x*dt)/(radius^3);
v_y_new=v_y-(4*pi^2*y*dt)/(radius^3);
x_new=x+v_x_new*dt;
y_new=y+v_y_new*dt;
plot(x_new,y_new,'-k');
v_x=v_x_new;
v_y=v_y_new;
x=x_new;
y=y_new;
end;

kemudian dipanggil di command window


>> dt1=0.005;
>> dt3=0.05;
>> dt2=0.01;
>> v_y=2*pi;
>> subplot 311
>> [x_new1,y_new1]=Orbit_Planet(dt1,npoints,v_y);
>> plot(x_new1,y_new1,'b');
>> subplot 312
>> [x_new2,y_new2]=Orbit_Planet(dt2,npoints,v_y);
>> plot(x_new2,y_new2,'r');
>> subplot 313
>> [x_new3,y_new3]=Orbit_Planet(dt3,npoints,v_y);
>> plot(x_new3,y_new3,'g')

y(AU)

0.5
0
-0.5
-1
-1

-0.8

-0.6

-0.4

-0.2

0
x(AU)

0.2

0.4

0.6

0.8

-0.8

-0.6

-0.4

-0.2

0
x(AU)

0.2

0.4

0.6

0.8

-0.8

-0.6

-0.4

-0.2

0
x(AU)

0.2

0.4

0.6

0.8

y(AU)

0.5
0
-0.5
-1
-1
1

y(AU)

0.5
0
-0.5
-1
-1

3.
Mengetik function m-file:

function [x_new,y_new]=Orbit_Planet (dt,npoints,v_y)


x=1;
y=0;
v_x=0;
plot(0,0,'oy','MarkerSize',30,'MarkerFaceColor','yellow')
axis([-1 1 -1 1]);
xlabel('x(AU)');
ylabel('y(AU)');
hold on;
for step = 1:npoints-1;
radius=sqrt(x^2+y^2);
v_x_new=v_x-(4*pi^2*x*dt)/(radius^3);
v_y_new=v_y-(4*pi^2*y*dt)/(radius^3);
x_new=x+v_x_new*dt;
y_new=y+v_y_new*dt;
plot(x_new,y_new,'-k');
v_x=v_x_new;
v_y=v_y_new;
x=x_new;
y=y_new;
end;

>> dt1=0.002;
>> dt2=0.05;
>> dt3=0.002;
>> v_y1=4;
>> v_y2=4;
>> v_y3=8;
>> npoints1=500;
>> npoints2=500;
>> npoints3=2500;
>> subplot 311
>> [x_new1,y_new1]=Orbit_Planet(dt1,npoints1,v_y1);
>> plot(x_new1,y_new1,'b');
>> title('dt=0.002;v_y=4')
>> subplot 312
>> [x_new2,y_new2]=Orbit_Planet(dt2,npoints2,v_y2);
>> plot(x_new2,y_new2,'r');

>> title('dt=0.05;v_y=4')
>> subplot 313
>> [x_new3,y_new3]=Orbit_Planet(dt3,npoints3,v_y3);
>> plot(x_new2,y_new2,'r');
>> title('dt=0.002;v_y=8')

dt=0.002;vy=4

y(AU)

1
0
-1
-1

-0.8

-0.6

-0.4

-0.2

0.4

0.6

0.8

-0.8

-0.6

-0.4

-0.2

0.4

0.6

0.8

-0.8

-0.6

-0.4

-0.2

0.4

0.6

0.8

y(AU)

1
0
-1
-1

1
y(AU)

0
0.2
x(AU)
dt=0.05;vy=4

0
0.2
x(AU)
dt=0.002;vy=8

0
-1
-1

0
x(AU)

0.2

You might also like