How to run this code on any inputs?Newton
Ältere Kommentare anzeigen
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 Kommentare
Geoff Hayes
am 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
am 22 Sep. 2014
Stephen23
am 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!
Akzeptierte Antwort
Weitere Antworten (1)
Stephen23
am 22 Sep. 2014
1 Stimme
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 Kommentar
cakey
am 23 Sep. 2014
Kategorien
Mehr zu Get Started with MATLAB finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!