how to plot forward difference error against h values ?
Afficher commentaires plus anciens
% Here is the code which I wrote but I'm not sure about. I think there are errors and I dont understand the last part which says use a function thanks for helping.
a=1;
h=10.^[-1:-1:-10];
x=a;
tval=(1/x)-1
%Forward
x=a+h;
f1=2-x+log(x);
x=a;
f2=2-x+log(x);
f3=(f1-f2)./h
Eabs=abs(tval-f3)
plot(Eabs,h)

Réponses (1)
Dyuman Joshi
le 2 Mai 2022
So when you save what you have written in a file, that would be saved as a script file. You have to manually update different values for different results and run them each time.
So, for a function file you have to define the syntax, as mentioned in the web page above.
function output = function_name(input)
your_code...
end
and then you can get outputs by calling the file without running it manually.
Catégories
En savoir plus sur MATLAB dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!