Matlab Script Accuracy of Results
Afficher commentaires plus anciens
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)
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!