Help with plotting a specific point on a graph
Mostrar comentarios más antiguos
I am pasting the function I am working on below. I added to it - just the part where the optimal h for backward difference is calculated. Can someone help me plot just the value hOptBackDiff on the graph as it exist?
I tried:
loglog(h,err1,'ro',h,err2,'b*',hOptBackDiff,err3, 'k*', 'markers', 20);
Here are the calculations:
% calculate optimal h for backward difference
hOptBackDiff=2*sqrt((eps/abs(tdf2)));
% not sure which possibility list to use
% possiblehlist=[truedf2(x), truedf2(x-h)];
possiblehlist=[truedf2(x), tdf2-hOptBackDiff];
M2=max(possiblehlist);
hOptBackDiff=2*sqrt((eps/abs(M2))); % I want to plot this value in the graph below
The graphing portion of the function looks like this:
err1=abs(df-df1);
err2=abs(df-df2);
err3=abs(df-tdf2);
% PLOT THE APPROXIMATION ERRORS AS A FUNCTION OF STEPSIZE
figure
loglog(h,err1,'ro',h,err2,'b*',hOptBackDiff,err3, 'k*', 'markers', 20);
% loglog(hOptBackDiff,err3, 'k*', 'markers', 20);
% LINEAR REGRESSION OF LOG-LOG RELATIONSHIPS (ONLY IN REGION GOVERNED BY TRUNCATION ERROR)
coef1=polyfit(log(h(end-4:end)),log(err1(end-4:end)),1);
coef2=polyfit(log(h(end-4:end)),log(err2(end-4:end)),1);
hold on % add the best-fit lines to the plot
loglog(h(end-4:end),exp(coef1(2))*h(end-4:end).^coef1(1),'r-');
loglog(h(end-4:end),exp(coef2(2))*h(end-4:end).^coef2(1),'b-');
% LABEL THE PLOT
set(gca,'fontsize',14) % be kind to the instructor's aging eyes!
xlabel('h')
ylabel('error')
legend('back diff','central diff',...
['slope = ',num2str(coef1(1),4)],['slope = ',num2str(coef2(1),4)],...
'Location','BestOutside');
title(['at x = ',num2str(x)])
%ALLOW USER TO VIEW EACH PLOT BEFORE MOVING ON TO THE NEXT
if xi<length(allx)
disp('Hit any key to continue...')
pause
end
end
figure(gcf)
Thanks in advance!
Respuestas (0)
Categorías
Más información sobre 2-D and 3-D Plots en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!