how can i get the graph of this iterative sequence
t=@(n)(1/(n+2)^2);r=1/5;
g=@(x)((x-1)/(exp(x)));
tolerance=0.000001;
k=100;
x=zeros(1,k);
x(1)=0.3977;
for n=1:k
x(n+1)=(1-(r)*g(x(n)))*(1-t(n))*x(n);
if abs(x(n+1)-x(n))<tolerance
fprintf('The sequence converges after %d iterations for tolerance = %f', n, tolerance)
break;
end
end
x=x(1:n+1); %discard the zeros
format long
disp(x)

 채택된 답변

Torsten
Torsten 2023년 5월 20일
편집: Torsten 2023년 5월 20일

0 개 추천

Add the command
plot(1:n+1,x)
at the end of your code.

댓글 수: 2

Basha
Basha 2023년 5월 21일
is it possible to dispaly more than one graph by changing x(1)?
t=@(n)(1/(n+2)^2);r=1/5;
g=@(x)((x-1)/(exp(x)));
tolerance=0.000001;
k=100;
N=20;
hold on
for NN=1:N
x(1)=rand;
for n=1:k
x(n+1)=(1-(r)*g(x(n)))*(1-t(n))*x(n);
if abs(x(n+1)-x(n))<tolerance
fprintf('The sequence converges after %d iterations for tolerance = %f', n, tolerance)
break;
end
end
plot(1:n+1,x)
end
hold off
grid on

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 App Building에 대해 자세히 알아보기

제품

릴리스

R2023a

태그

질문:

2023년 5월 20일

댓글:

2023년 5월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by