フィルターのクリア

Subplot within for loop is duplicating/overlaying graphs.

2 ビュー (過去 30 日間)
Lewis
Lewis 2022 年 3 月 25 日
コメント済み: Lewis 2022 年 3 月 25 日
The problem I am having is that the second plot seems to be overlaying the first one as well.
clear
syms x
f(x)=1/cosh(x)
N=[4,14] %defines interpolating polynomial degree
for k=1:length(N) %iterates over the values in array N
for i=0:N(k) %iterates over each point
xcheb(i+1)=-0.5*cos((((2*i)+1)/(((2*N(k)))+2)*pi)); %creates array of Chebyshev points
fvals(i+1)=1/cosh(xcheb(i+1)); %creates array of values of f(x) at each Chebyshev point
end
temp=1; %initialises temporary variable used in the Lagrange method
poly(k)=0; %initialises poly; the integrating polynomial
for i=1:N(k)+1
for j=1:N(k)+1
if i~=j
temp=temp*(x-xcheb(j))/((xcheb(i)-xcheb(j)));
end
end
poly=poly+(fvals(i)*temp);
temp=1;
end
subplot(3,1,k)
fplot(poly,[-0.5,0.5],'r')
end
subplot(3,1,3)
fplot(f,[-0.5,0.5],'g')
Thanks

採用された回答

Walter Roberson
Walter Roberson 2022 年 3 月 25 日
poly(k)=0; %initialises poly; the integrating polynomial
That makes poly a vector . On the second iteration of k, poly is going to have length 2.
poly=poly+(fvals(i)*temp);
Vector plus scalar equals vector, so the left side is going to be a vector.
fplot(poly,[-0.5,0.5],'r')
All elements of the vector of symbolic experssions are plotted.
  1 件のコメント
Lewis
Lewis 2022 年 3 月 25 日
Thank you, I forgot to include the 'k' index in the fplot line!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumber Theory についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by