Many past learners share their MATLAB/Python code (not just final answers) on GitHub. Search for:
Example use: Compare your Newton-Raphson loop structure to a peer’s on GitHub. See if you forgot to update the derivative at each iteration.
Instead of a generic answer, here’s what a typical correct response looks like for a common coding problem:
Prompt: Write a MATLAB function
[root, iter] = newton_raphson(f, df, x0, tol)that returns the root offgiven its derivativedf, starting atx0, with tolerancetol.Correct function structure:
function [root, iter] = newton_raphson(f, df, x0, tol) iter = 0; x = x0; while abs(f(x)) > tol x = x - f(x)/df(x); iter = iter + 1; if iter > 1000 error('Did not converge'); end end root = x; endExpected test output for
f(x)=x^3-2,df=3*x^2,x0=1,tol=1e-6:root ≈ 1.259921,iter = 6
Prof. Chasnov has published free companion eBooks (on GitHub and his website) that contain many worked-out examples. While not identical to quiz questions, they mirror the exact methods.
Many past learners share their MATLAB/Python code (not just final answers) on GitHub. Search for:
Example use: Compare your Newton-Raphson loop structure to a peer’s on GitHub. See if you forgot to update the derivative at each iteration. numerical methods for engineers coursera answers
Instead of a generic answer, here’s what a typical correct response looks like for a common coding problem: Many past learners share their MATLAB/Python code (not
Prompt: Write a MATLAB function
[root, iter] = newton_raphson(f, df, x0, tol)that returns the root offgiven its derivativedf, starting atx0, with tolerancetol. Example use: Compare your Newton-Raphson loop structure toCorrect function structure:
function [root, iter] = newton_raphson(f, df, x0, tol) iter = 0; x = x0; while abs(f(x)) > tol x = x - f(x)/df(x); iter = iter + 1; if iter > 1000 error('Did not converge'); end end root = x; endExpected test output for
f(x)=x^3-2,df=3*x^2,x0=1,tol=1e-6:root ≈ 1.259921,iter = 6
Prof. Chasnov has published free companion eBooks (on GitHub and his website) that contain many worked-out examples. While not identical to quiz questions, they mirror the exact methods.