clc,clf,clear
maxit=1000;
g=9.81; theta0=50*pi/180; v0=5; CR=0.83;
j=1;t(j)=0;x=0;y=0;
xx=x;yy=y;
plot(x,y,'o','MarkerFaceColor','b','MarkerSize',8)
xmax=8; axis([0 xmax 0 0.8])
M(1)=getframe;
dt=1/128;
j=1; xxx=0; iter=0;
while(1)
tt=0;
timpact=2*v0*sin(theta0)/g;
ximpact=v0*cos(theta0)*timpact;
while(1)
j=j+1;
h=dt;
if tt+h>timpact,h=timpact-tt;end
t(j)=t(j-1)+h;
tt=tt+h;
x=xxx+v0*cos(theta0)*tt;
y=v0*sin(theta0)*tt-0.5*g*tt^2;
xx=[xx x];yy=[yy y];
plot(xx,yy,':',x,y,'o','MarkerFaceColor','b','MarkerSize',8)
axis([0 xmax 0 0.8])
M(j)=getframe;
iter=iter+1;
if tt>=timpact, break, end
end
v0=CR*v0;
xxx=x;
if x>=xmax|iter>=maxit,break,end
end
pause
clf
axis([0 xmax 0 0.8])
movie(M,1,36)

댓글 수: 1

KSSV
KSSV 2018년 10월 3일
Simple...you decide what inputs you want...and make it a function.

댓글을 달려면 로그인하십시오.

답변 (1개)

madhan ravi
madhan ravi 2018년 10월 3일
편집: madhan ravi 2018년 10월 3일

0 개 추천

function movie_example %an example you can modify inserting inputs theta0, v0 , CR and so on
%clc,clf,clear %EDITED after Guillaume's comment
maxit=1000;
g=9.81; theta0=50*pi/180; v0=5; CR=0.83;
j=1;t(j)=0;x=0;y=0;
xx=x;yy=y;
plot(x,y,'o','MarkerFaceColor','b','MarkerSize',8)
xmax=8; axis([0 xmax 0 0.8])
M(1)=getframe;
dt=1/128;
j=1; xxx=0; iter=0;
while(1)
tt=0;
timpact=2*v0*sin(theta0)/g;
ximpact=v0*cos(theta0)*timpact;
while(1)
j=j+1;
h=dt;
if tt+h>timpact,h=timpact-tt;end
t(j)=t(j-1)+h;
tt=tt+h;
x=xxx+v0*cos(theta0)*tt;
y=v0*sin(theta0)*tt-0.5*g*tt^2;
xx=[xx x];yy=[yy y];
plot(xx,yy,':',x,y,'o','MarkerFaceColor','b','MarkerSize',8)
axis([0 xmax 0 0.8])
M(j)=getframe;
iter=iter+1;
if tt>=timpact, break, end
end
v0=CR*v0;
xxx=x;
if x>=xmax|iter>=maxit,break,end
end
pause
%clf
axis([0 xmax 0 0.8])
movie(M,1,36)
end
Remark: Download the attached file and type movie_example in command window to test the function file

댓글 수: 3

Guillaume
Guillaume 2018년 10월 3일
clear at the start of a function is completely pointless. And I would argue that clc and clf have also no place in a function.
Stephen23
Stephen23 2018년 10월 3일
"clear at the start of a function is completely pointless"
Not just pointless, but totally counterproductive and wastes a lot of time.
madhan ravi
madhan ravi 2018년 10월 3일
편집: madhan ravi 2018년 10월 3일
Thank you both for valuable suggestion rectified the mistake.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터 및 File Exchange에서 Programming에 대해 자세히 알아보기

질문:

2018년 10월 3일

편집:

2018년 10월 3일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by