Forward difference and central difference help - expected rates of convergence

48 views (last 30 days)
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 Comments
Savannah Phillips
Savannah Phillips on 18 Mar 2020
that's just a function used to find the forward and central difference (it's all correct)

Sign in to comment.

Answers (1)

Ayush Gupta
Ayush Gupta on 4 Jun 2020
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

Categories

Find more on Graphics 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!