How to make a plot of iteration count vs residual error?
5 views (last 30 days)
Show older comments
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)
0 Comments
Answers (1)
Mathieu NOE
on 5 Oct 2021
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)
2 Comments
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!