フィルターのクリア

How can I create a 2-D movie for my simulation?

4 ビュー (過去 30 日間)
Yuxing Zhang
Yuxing Zhang 2018 年 11 月 27 日
コメント済み: Yuxing Zhang 2018 年 11 月 28 日
I am writing a solver for the streamfunction equations (2) and compelete the solver part already.
a.png
But it still requests to simulate the Gaussian vortices situations. Like
(1) Two oppositely “charged” Gaussian vortices next to each other.
(2) Two same “charged” Gaussian vortices next to each other.
and make a 2-D movie for the simulation, can anyone tell me how to get this, the below is my solver code.
n=64;
N=n*n;
e0=zeros(N,1);
e1=ones(N,1);
e2=e1; e4=e0; dx=20/64;
v=0.001;
for j=1:n
e2(n*j)=0;
e4(n*j)=1;
end
e3(2:N,1)=e2(1:N-1,1); e3(1,1)=e2(N,1);
e5(2:N,1)=e4(1:N-1,1); e5(1,1)=e4(N,1);
a=spdiags([e1 e1 e5 e2 -4*e1 e3 e4 e1 e1],[-(N-n) -n -n+1 -1 0 1 n-1 n (N-n)],N,N);
a(1,1)=2;
b=spdiags([e1 -e1 e0 e1 -e1],[-(N-n) -n 0 n (N-n)],N,N);
e6(1:N-1,1)=e5(2:N,1); e6(N,1)=e5(1,1); % positions
e7(2:N,1)=e2(1:N-1,1); e7(N,1)=e2(1,1);
c=spdiags([e5 -e2 -e0 e7 -e6 ],[ -n+1 -1 0 1 n-1 ],N,N);
A=(a)/dx^2;
B=(b)/(2*dx);
C=(c)/(2*dx);
L=20;
x2=linspace(-L/2,L/2,n+1);
xspan=x2(1:n);yspan=xspan;
[xspan,yspan]=meshgrid(xspan,yspan);
w0=exp(-xspan.^2-(yspan.^2/20));
w0=reshape(w0,4096,1);
tspan=0:0.5:4;
v=0.001;
[t,wsol1]=ode45(@(t,w)rhseq(t,w,A,B,C,v),tspan,w0);
function rhs=rhseq(t,w,A,B,C,v)
psi=A\w;
rhs=(C*psi).*(B*w)-(B*psi).*(C*w)+(v.*A*w);
end

回答 (1 件)

KSSV
KSSV 2018 年 11 月 28 日
The best option would be to make a .gif. YOu can make such a file using the below code:
h = figure;
axis tight manual % this ensures that getframe() returns a consistent size
filename = 'testAnimated.gif';
for n = 1:0.5:5
% Draw plot for y = x.^n
x = 0:0.01:1;
y = x.^n;
plot(x,y)
drawnow
% Capture the plot as an image
frame = getframe(h);
im = frame2im(frame);
[imind,cm] = rgb2ind(im,256);
% Write to the GIF File
if n == 1
imwrite(imind,cm,filename,'gif', 'Loopcount',inf);
else
imwrite(imind,cm,filename,'gif','WriteMode','append');
end
end

カテゴリ

Help Center および File ExchangeAnimation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by