Effacer les filtres
Effacer les filtres

I need to use Newton's method to solve f(x). Can any one tell me what's wrong of my code and how to improve it.

2 vues (au cours des 30 derniers jours)

Réponses (2)

Yongjian Feng
Yongjian Feng le 9 Fév 2022
what i s your dx?

David Hill
David Hill le 9 Fév 2022
a=1:4;
tiny=1e-10;
x=ones(size(a));%this will not work well for the initial guess
for k=1:length(a)
f=@(x)tan(x)+a(k)*sin(x)./x;
fp=@(x)sec(x)^2-a(k)*sin(x)/(x^2)+a(k)*cos(x)/x;
rat=1;
while rat>tiny
dx=f(x(k))/fp(x(k));
x(k)=x(k)-dx;
rat=abs(dx/x(k));
end
end
If you look at your plot, you will realize that there are lots of crossings. Your initial guess for x must be close to the crossing you want.

Catégories

En savoir plus sur Mathematics dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by