필터 지우기
필터 지우기

how to animate Plot

조회 수: 4 (최근 30일)
Abhinandan Angadi
Abhinandan Angadi 2021년 10월 11일
댓글: Abhinandan Angadi 2021년 10월 14일
I'm trying to animate the below code,but it's not coming up as expected . Can somebody help me?
clear all
close all
clc
%number of terms in taylor series
n = 34;
%number of x values
n_x = 10;
x = linspace(0,15,n_x);
for j = 1:n_x
for i = 1:n
term(i) = x(j)^(i-1)/factorial(i-1);
end
taylor_series_approximation(j) = sum(term)
end
r = exp(x);
t = taylor_series_approximation;
plot(x,r,'color','g','linewidth',3)
hold on
plot(x,t,'*','color','r','markersize',5)
xlabel('x-axis')
ylabel('y-axis')
legend('Exact Expression','Taylor Series approx')
Result-
This is the code I've written to animate the above plot ,but its not showing up
clear all
close all
clc
%number of terms in taylor series
n = 34;
%number of x values
n_x = 10;
x = linspace(0,15,n_x);
for j = 1:n_x
for i = 1:n
term(i) = x(j)^(i-1)/factorial(i-1);
end
taylor_series_approximation(j) = sum(term)
end
r = exp(x);
t = taylor_series_approximation;
ax1 = subplot(1,1,1)
hold on
grid on
h1 = animatedline(ax1,'color','g','linewidth',3)
p2 = plot(ax1,x,t,'*','color','r','markersize',5)
for k = 1:length(n_x)
addpoints(h1,x(k),r(k))
p2.XData = [x(k)];
p2.YData = [t(k)];
drawnow;
end
xlabel('x-axis')
ylabel('y-axis')
legend('Exact Expression','Taylor Series approx')
help me with this
  댓글 수: 1
Abhinandan Angadi
Abhinandan Angadi 2021년 10월 14일
I'm unable to animate this. Can someone help with this?

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

답변 (1개)

KSSV
KSSV 2021년 10월 11일
  댓글 수: 1
Abhinandan Angadi
Abhinandan Angadi 2021년 10월 14일
Thanks. But Its still not clear . I couldn't understand how to get it done.

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

카테고리

Help CenterFile Exchange에서 Animation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by