% this file determines the order and the constant C of the choosen discretization method % n Number of subdivisions of the intrvall[0,1] % h=1/n length of a stepp % error maximal difference of the exact solution u and its numerical approximation on the grid % V a vector used to compare graphically the behaviour of the error % Why do we express the error (in dependence of h) with loglog? % error = C*h^order = C*exp(order*log(h)) % log(error) = log(C) + order*log(h) % loglog(h,error) plots log(error) over log(h) % => an even with % incrementation = order % the value of the even at x=0 = log(C) % the plot comparse with a of the same disp('Enter the method as a string and put the second argument plot to 0') disp('for example:') f=input('`FpointDi1(n,0)` :'); error=[]; for n=10:10:100 error=[error,eval(f)]; end % the different distances between the nodes n=10:10:100; % calculating the order of the choosen method log_e=log(error); log_n=log(n); % order as average incrementation Ord =(log_e(2:10)-log_e(1:9))./(-log_n(2:10)+log_n(1:9)); Ord = round(mean(Ord)); % V: vector to compare V=n.^-Ord; % calculating the constant C C=mean(error./V); % preparations for the plot Ord = num2str(Ord); C=num2str(C); loglog(n,error,'r') hold on loglog(n,error,'r+') loglog(n,V) hold off title('graphical determination of the order of the chosen method') xlabel('n') ylabel('error & V=vector to compare') if str2num(C)>1 text(0.7,0.8,'error','color','r','units','normalized') text(0.77,0.8,'= Cn','color','r','units','normalized') text(0.77,0.812,'~','color','r','units','normalized') text(0.82,0.83,'-order','color','r','units','normalized') text(0.1,0.2,'V =','color','b','units','normalized') text(0.15,0.2,'n','color','b','units','normalized') text(0.16,0.23,'-','color','b','units','normalized') text(0.17,0.23,Ord,'color','b','units','normalized') else text(0.1,0.2,'error','color','r','units','normalized') text(0.17,0.2,'= Cn','color','r','units','normalized') text(0.17,0.212,'~','color','r','units','normalized') text(0.22,0.23,'-order','color','r','units','normalized') text(0.7,0.8,'V =','color','b','units','normalized') text(0.75,0.8,'n','color','b','units','normalized') text(0.76,0.83,'-','color','b','units','normalized') text(0.77,0.83,Ord,'color','b','units','normalized') end text(0.28,0.95,'method ','color','k','units','normalized') text(0.42,0.95,'=','color','k','units','normalized') text(0.45,0.95,f,'color','k','units','normalized') text(0.3,0.9,'order ','color','k','units','normalized') text(0.42,0.9,'=','color','k','units','normalized') text(0.45,0.9,Ord,'color','k','units','normalized') text(0.39,0.85,'C ','color','k','units','normalized') text(0.42,0.85,'=','color','k','units','normalized') text(0.45,0.85,C,'color','k','units','normalized')