matlab が初めてで、与えられたコードを少し理解できません。
x = 1; % initial guess = 1
Tol = 5e-9; % correct to 8 decimal places
count = 0;
f=0.54030231; % f(1)= 0.54030231
fprintf('step x f(x)\n')
fprintf('---- ----------- ----------\n')
fprintf('%1i %12.8f %12.8f\n',count,x,f)
while abs(f)>Tol %loop until the absolute value of f is smaller than tolerance
count = count + 1
deriv = -sin(x); ; % first derivative of f(x)
x2 = x - (f/deriv); % new value of x
x = x2;
f = cos (x); % new value of f(x)
fprintf('%3i %12.8f %12.8f\n',count,x,f)
end
プログラムは、私が理解している方程式の根を見つけるためのニュートン法です。
私が理解していないのは、この部分です:
fprintf('---- ----------- ----------\n')
fprintf('%1i %12.8f %12.8f\n',count,x,f)
質問:
- 2 行目の最後のビットが n で除算されるのはなぜですか?
- %1i、%12.8f などの 2 行目の数字は何ですか?
- これは、その後に書かれている「count、x、f」とどのように機能しますか?
ありがとう