How to plot a function dependent on no. of iterations, provided it plots till nth iteration where n is the number where the function is converged?
3 次查看(过去 30 天)
显示 更早的评论
Hello All,
I am trying to plot a function vs no. of iterations. In the for loop, i have given the convergence condition, but I am unable to plot for f(x) vs no. iterations (till convergence). Please help.
Its of the form:
for m=1:n
pu(m)=(-1)^m)/((2*m)+1))*(exp(-((2*m)+1)))
e = e+pu;
if (abs(pu)/e)<(10^(-6)) %convergence check
break
end
end
hold all
plot(1:n,pu,'linestyle','none','marker','*')
0 个评论
采纳的回答
VBBV
2022-1-28
编辑:VBBV
2022-1-29
n= 10;
e = 0;
for m=1:n
pu(m)=(-1)^m/((2*m)+1)*(exp(-((2*m)+1)))
e = e+pu(m);
if (abs(pu(m))/e)>(10^(-6)) %convergence check
break
end
end
hold all
plot(1:n,pu,'linestyle','-','marker','.')
Check the convergence condition
7 个评论
VBBV
2022-1-29
legend(mrkr{cidx},legendInfo)
Put this line inside the inner for loop. After legendInfo. Everytime the inner for loop exits, it's over written with initial values for mrkr and clr index.
VBBV
2022-1-29
编辑:VBBV
2022-1-29
u=zeros(n,npoints); % change also This line in beginning
u(m,cidx)=pu(m);
hold all
plot(1:m,u(1:m,cidx),'linestyle','none','marker',mrkr{cidx},'Color',clr{cidx})
You also need to change these two lines inside the for loop. As you can see the u value is dependent on pu which is again varying with each outer iteration of for loop.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Performance 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!