How to Implement Newton-Raphsons Method in Matlab?

In summary, the conversation discusses creating an applicator for the Matlab Newton-Raphsons method using only a function handle, initial value, and desired number of iterations. The question is how to take the value from the previous iteration onto the next one in a loop. The correct code for this task is also provided.
  • #1
Dukefool
5
0
My objective is to create an applicator for the Matlab Newton-Raphsons method using only a function handle, the initial value and the number of iterations desired. I'm extremely new to Matlab and programming so bare with me for being programming deficient. My question is when making a loop, how can you take the value made from x1 onto x2? For example if I wanted to approximate x2-5 with 6 iterations at the initial value of 100, how would I be able to take the value from x5 onto x6?

Here's what I have right now. I know it is absolutely wrong.
function y = myNewton(f,a,n)
syms x
x(0)=a;
df=diff(f(x),n);
for i=1:n
x=x(i-1)-f(x(i-1))/diff(f(x),i-1)
end
y=x
 
Physics news on Phys.org
  • #2
;end The correct code should look like this: function y = myNewton(f,a,n)x(1) = a;for i=2:n+1x(i)=x(i-1)-f(x(i-1))/diff(f(x(i-1)));endy = x(n+1);end
 

Related to How to Implement Newton-Raphsons Method in Matlab?

1. What is the Matlab Newton-Raphsons method?

The Matlab Newton-Raphsons method is a numerical algorithm used for finding roots of a given function. It is based on the concept of approximating a function using its tangent line at a particular point and iteratively improving the guess until the desired accuracy is achieved.

2. How does the Matlab Newton-Raphsons method work?

The method starts with an initial guess for the root of the function. Then, the tangent line to the function at that point is calculated, and its x-intercept is taken as the next guess. This process is repeated iteratively until the desired accuracy is achieved.

3. What are the advantages of using the Matlab Newton-Raphsons method?

The method is relatively simple and easy to implement. It also converges quickly to the root of the function, making it an efficient option for finding roots of functions that are difficult to solve analytically.

4. What are the limitations of the Matlab Newton-Raphsons method?

The method may fail to converge if the initial guess is far from the actual root or if the function has multiple roots. It also requires the calculation of the derivative of the function, which may not always be available or easy to compute.

5. How can I use the Matlab Newton-Raphsons method in my code?

To use the method in your code, you can define the function and its derivative using Matlab's syntax. Then, you can use a loop to perform the iterative calculations until the desired accuracy is achieved. The final value will be the estimated root of the function.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
678
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
222
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
14
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
Back
Top