フィルターのクリア

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 Center および File ExchangeAnimation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by