newton final

mail@pastecode.io avatar
unknown
matlab
2 years ago
453 B
0
Indexable
Never
function newtonAprox(h)
hDouble = str2double(h);

syms x f(x)
f(x) = cos((3*x^2) + 5*x);
secondDerative = diff(f,x,2)
fplot(secondDerative)
hold on
syms aprox(x)
aprox(x) = (f(x+4*hDouble)- 2*f(x) + f(x-4*hDouble))/(16*hDouble^2);
fplot(aprox)
hold off

z=hDouble;
difs = [];

while z <= 1+3/10
    dif = aprox(z) - secondDerative(z)
    difs = [difs, dif];
    z=z+hDouble;
end

error = max(difs)
disp(error)
end