Borrar filtros
Borrar filtros

how to animate Plot

4 visualizaciones (últimos 30 días)
Abhinandan Angadi
Abhinandan Angadi el 11 de Oct. de 2021
Comentada: Abhinandan Angadi el 14 de Oct. de 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 comentario
Abhinandan Angadi
Abhinandan Angadi el 14 de Oct. de 2021
I'm unable to animate this. Can someone help with this?

Iniciar sesión para comentar.

Respuestas (1)

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

Iniciar sesión para comentar.

Categorías

Más información sobre Animation en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by