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)

답변 (1개)
Dyuman Joshi
2022년 5월 2일
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.
카테고리
도움말 센터 및 File Exchange에서 MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!