how to plot forward difference error against h values ?

% 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)

Answers (1)

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.

Categories

Find more on MATLAB in Help Center and File Exchange

Products

Release

R2021b

Asked:

on 1 May 2022

Answered:

on 2 May 2022

Community Treasure Hunt

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

Start Hunting!