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)

Antworten (1)

Dyuman Joshi
Dyuman Joshi am 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.

Kategorien

Mehr zu MATLAB finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2021b

Gefragt:

am 1 Mai 2022

Beantwortet:

am 2 Mai 2022

Community Treasure Hunt

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

Start Hunting!

Translated by