how to animate Plot

6 views (last 30 days)
Abhinandan Angadi
Abhinandan Angadi on 11 Oct 2021
Commented: Abhinandan Angadi on 14 Oct 2021
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 Comment
Abhinandan Angadi
Abhinandan Angadi on 14 Oct 2021
I'm unable to animate this. Can someone help with this?

Sign in to comment.

Answers (1)

KSSV
KSSV on 11 Oct 2021
  1 Comment
Abhinandan Angadi
Abhinandan Angadi on 14 Oct 2021
Thanks. But Its still not clear . I couldn't understand how to get it done.

Sign in to comment.

Categories

Find more on Animation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!