In: Computer Science
Using the range 0 ≤ x ≤ 1 and 0 ≤ t ≤ 1 make an animated plot of:
1.) y1(x,t)=cos(4πt)sin(πx)
2.) y2(x,t)=cos(8πt)sin(2πx)
using matlab
Solution :
Following are the Matlab code for both the part with output :
a)
%range of x
x=0:0.01:1;
%range of y
t=0:0.01:1;
%given function a)
y=cos(4*pi*t).*sin(pi*x);
curve=animatedline('Color','r','Marker','o');
set(gca,'XLim',[0,1],'YLim',[-1,1]);
grid on;
legend("animated plot 1");
for i=1:length(x)
addpoints(curve,x(i),y(i));
drawnow
end
Code demo :
b)
%range of x
x=0:0.01:1;
%range of y
t=0:0.01:1;
%given function b)
y=cos(8*pi*t).*sin(2*pi*x);
curve=animatedline('Color','b','Marker','o');
set(gca,'XLim',[0,1],'YLim',[-1,1]);
grid on;
legend("animated plot 2");
for i=1:length(x)
addpoints(curve,x(i),y(i));
drawnow
end
Code demo :