Filter löschen
Filter löschen

how to animate Plot

4 Ansichten (letzte 30 Tage)
Abhinandan Angadi
Abhinandan Angadi am 11 Okt. 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 Kommentar
Abhinandan Angadi
Abhinandan Angadi am 14 Okt. 2021
I'm unable to animate this. Can someone help with this?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

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

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Animation finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by