How to run this code on any inputs?Newton
Afficher commentaires plus anciens
function [p,k] = newton(f,df,p0,tol)
for k=1:100
p = p0 - f(p0)/df(p0);
if abs(p-p0)<tol, break; end
p0 = p;
end
I have that but where do I put the tolerance, the function and everything else for it to run. I'm really new at all this.
4 commentaires
Geoff Hayes
le 21 Sep 2014
cakey - presumably f and df are function handles and your code makes use of the function f and its derivative df. Also since you are using the tolerance tol as a condition to break out of the loop and the initial point p0, it isn't clear to me what you mean by where do I put the tolerance, the function and everything else for it to run. Please clarify what it is that you need help with.
cakey
le 22 Sep 2014
Stephen23
le 22 Sep 2014
Read about function handles, it might help. And use the contents browser, which is on the left-hand side of the help window, to discover related topics... it really is very handy!
Réponse acceptée
Plus de réponses (1)
Stephen23
le 22 Sep 2014
1 vote
What you have is a function, which can be run to create some outputs. It could be good to revise MATLAB's comprehensive help on calling functions . If you are learning MATLAB, you will have to get used to doing a lot of reading of help pages. But don't worry, MATLAB's help pages are really quite good, with plenty of examples to try, and explanations of concepts that you need to understand. You should learn to navigate using the help contents browser too. Good luck!
1 commentaire
cakey
le 23 Sep 2014
Catégories
En savoir plus sur Whos dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!