How to make a plot of iteration count vs residual error?

조회 수: 6 (최근 30일)
DHIVYA CHANDRASEKARAN
DHIVYA CHANDRASEKARAN 2021년 10월 5일
댓글: Mathieu NOE 2021년 10월 25일
How to make table for this iteration versus residual error. I try to make table but not got it. In which line and what matlab code need to include for this below program.
for k=1:n
a=(k);b=(k+1);
for kk=1:10
pt=0.5*((b-a)*(kk)+(b+a));
rf=(((a11(pt)*d3fn(pt))+(a12(pt)*d2fn(pt))+(a13(pt)*dfn(pt))+...
(a14(pt)*fn(pt)))*dfn(pt))*(kk)*0.5*(b-a);
rg=(((c11(pt)*d2gn(pt))+(c12(pt)*dgn(pt))+...
(c13(pt)*gn(pt)))*gn(pt))*(kk)*0.5*(b-a);
ry=(((d11(pt)*d2yn(pt))+(d12(pt)*dyn(pt))+...
(d13(pt)*yn(pt)))*yn(pt))*(kk)*0.5*(b-a);
rrf(iter) = norm(rf,inf);
rrg(iter) = norm(rg,inf);
rry(iter) = norm(ry,inf);
end
end
semilogy(1:iter,rrf,'-*',1:iter,rrg,'-*',1:iter,rry,'-*','linewidth',1.8)

답변 (1개)

Mathieu NOE
Mathieu NOE 2021년 10월 5일
Hello
iter was not initialized nor incremented in your loop
this should work now (could not test it as variables are not initialised in the code you posted)
iter = 0; % added this
for k=1:n
a=(k);b=(k+1);
for kk=1:10
iter = iter+1; % added this also
pt=0.5*((b-a)*(kk)+(b+a));
rf=(((a11(pt)*d3fn(pt))+(a12(pt)*d2fn(pt))+(a13(pt)*dfn(pt))+...
(a14(pt)*fn(pt)))*dfn(pt))*(kk)*0.5*(b-a);
rg=(((c11(pt)*d2gn(pt))+(c12(pt)*dgn(pt))+...
(c13(pt)*gn(pt)))*gn(pt))*(kk)*0.5*(b-a);
ry=(((d11(pt)*d2yn(pt))+(d12(pt)*dyn(pt))+...
(d13(pt)*yn(pt)))*yn(pt))*(kk)*0.5*(b-a);
rrf(iter) = norm(rf,inf);
rrg(iter) = norm(rg,inf);
rry(iter) = norm(ry,inf);
end
end
semilogy(1:iter,rrf,'-*',1:iter,rrg,'-*',1:iter,rry,'-*','linewidth',1.8)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by