Forward difference and central difference help - expected rates of convergence

조회 수: 3 (최근 30일)
Hi, if anyone could help me with this question on my coursework I'd be really grateful! I've already had help on the first part, now it's just the second part:
Within your file , test your difference quotient formulas with h = 10^−i for i = 1, 2, . . . , 10. Plot the errors versus h in a figure with double-log axes. (This part I've already done)
Can you observe the expected rate of convergence (asymptotic behaviour as h → 0)? What happens for very small h? Hint: It may be helpful to include in your plot the graphs of functions r(h) = h^α with α the expected rates of convergence.
The mark scheme says that I need two error plots. Which is the second one? Is it r(h) = h^α? Do I need to plot the expected error? How would I go about doing that? Thank you in advance for your help!
Here is my code:
f = @(x) sin(x); % function handle
for i = 1:10
h(i) = 10.^(-i);
[fd(i),cd] = FDCD(f,0.9,h(i));
end
% f'(0) = 1 for this question
errors = 1 - fd; % Approximation error for forward difference quotient
% Setting the figure
figure
loglog(errors, h);
grid on;
% Formatting the plot
(just title, axes labels, etc)
I know that all this is right, but i have no idea what the second plot is spoken about in the mark sceme and how to go about making it, if it is r(h) = h^a. Thank you!
  댓글 수: 4
Savannah Phillips
Savannah Phillips 2020년 3월 18일
that's just a function used to find the forward and central difference (it's all correct)

댓글을 달려면 로그인하십시오.

답변 (1개)

Ayush Gupta
Ayush Gupta 2020년 6월 4일
Try using with this code for section 2
x=[-10:0.01:20];
dt = 0.00001;
values_y = [-10:0.01:20];
y1 = [-10:0.01:20];
values_error = [-10:0.01:20];
y2 = [-10:0.01:20];
for i =1:length(x)
values_y(i) = 1/(10^(x(i)));
y1(i) = log(values_y(i));
values_error(i) = (1/((10^(x(i)+dt)) - values_y(i)))/dt;
y2(i) = log(values_error(i));
end
hold on
plot(x,y1)
plot(x,y2)
hold off

카테고리

Help CenterFile Exchange에서 Grid Lines, Tick Values, and Labels에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by