MATLAB: The code below I’m trying to plot a loglog graph, but everytime I run the code I keep getting an empty graph, then when i use the brush i can see the points. can anyone help

empty graphsloglog

n=10;
x=0.2;
for i=1:n
h=1/i;
cf=dot([1 -2 1],[(cos(pi*(x+h))) cos(pi*x) cos(pi*(x-h))])/h^2;
rf=dot([2 -5 4 -1],[cos(pi*x) ;cos((pi*(x+h))) ;cos((pi*(x+2*h))); cos(pi*(x+3*h))])/h^2;
ec=abs((-pi^2*cos(pi*x))-cf);
er=abs((-pi^2*cos(pi*x))-rf);
loglog(h,ec,'g');
hold on
loglog(h,er,'r');
hold on
end
xlabel('h')
ylabel('ec + er')

Best Answer

You are only plotting one point at a time so you will not get connecting lines. But you have not specified any marker shape or marker size so you cannot see the markers.
Are you trying for lines or for a scatter plot?