我试图给代码添加边界,但有困扰搞清楚把它们放在哪里。该方程变为:F(X)= E ^(6×)+ 1.441e ^(2×) - 2.079e ^(4×) - 0.333 = 0,-1> = X < = 0将代码添加到代码中,matlab
function c = newton(x0, delta)
c = x0;
fc = f(x0);
fprintf('initial guess: c=%d, fc=%d\n',c,fc)
if abs(fc) <= delta % check to see if initial guess satisfies
return; % convergence criterion.
end;
while abs(fc) > delta,
fpc = fprime(c);
if fpc==0, % if fprime is 0, abort.
error('fprime is 0') % the error function prints message and exits
end;
c = c - fc/fpc; % Newton step
fc = f(c);
fprintf(' c=%d, fc=%d\n',c,fc)
end;
function fx = f(x)
fx = exp(6*x)+1.441*exp(2*x)-2.079*exp(4*x)-0.333; % Enter your function here.
return;
function fprimex = fprime(x)
fprimex = 6*exp(6*x)+6*exp(2*x)*(ln(2))^2-4*exp(4*x)*ln(8); % Enter the derivative of function
return;
如果你改变了变量名'C'到'x',它可能是更容易你明白了! –