Matlab Script Accuracy of Results
Show older comments
I'm trying to write a Matlab script that shows the order of accuracy of the forward and central differencing methods for the first derivative of f = exp (x) at x = 0. The graph attached is the result I'm looking for.
Here is what I have so far in forward differencing method but I'm kinda stuck. Can you show me where I made my mistakes.
clear all
close all
delx = 1;
x = 0;
y = exp(x);
fig = figure();
set(fig,'color','white')
plot(x,y,'LineWidth',2)
xlabel('x')
ylabel('y')
grid on
yderiv = exp(x);
fig = figure();
set(fig,'color','white')
plot(x,yderiv,'LineWidth',2)
xlabel('x')
ylabel('y')
grid on
%%%Forward Differencing
yderivest = (y(2:end) - y(1:end-1))./delx;
hold on
plot(x(2:end)-delx/2,yderivest,'r-','LineWidth',2)
Accepted Answer
More Answers (0)
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!