Solving Root Problem with Matlab Newton-Raphson Method

  • MATLAB
  • Thread starter arikrubin
  • Start date
  • Tags
    Matlab
In summary, the conversation is about a code written to find the root of a function using the element-by-element operator. The code initially had an error due to using a non-scalar and non-square matrix, but after adding the dot, the code still does not work and outputs an empty matrix. The individual is asking for help to fix the issue.
  • #1
arikrubin
2
0
hey
i have a question for u guys.
i have wrriten this code:

function[a]=search_root_3(x,e)
f1=x^3-10*x^2+15*x+3;
f11=diff(x^3-10*x^2+15*x+3,x,1);
if abs(f1)<=e
fprintf('the root is %d% \n');
return
end
while abs(f1)>=e
x=x-(f1/f11);
f1=x^3-10*x^2+15*x+3;
f11=diff(x^3-10*x^2+15*x+3,x,1);
end
a=x;
end
the goal is to find the root.
when i am trying to run this code i getting the next eror even though i have used f1 (exact form) in other codes seccessfully:
>> [a]=search_root_3(x1,e)
? Error using ==> mpower
Inputs must be a scalar and a square matrix.

Error in ==> search_root_3 at 10
f1=x^3-10*x^2+15*x+3;

i will be glad to get some help
thanx
arik
 
Physics news on Phys.org
  • #2
Use element-by-element operators, e.g.:
Code:
f1=x.^3-10*x.^2+15*x+3;
(Periods in front of operators.)
 
  • #3
hey thanx!
but now, even though i have added the dot tha mathlab still thinks that it is a mtrix.
this is the code:

function[a]=search_root_3(x,e)
f1=x.^3-10*x.^2+15*x+3;
f11=diff(x.^3-10*x.^2+15*x+3,x,1);
if abs(f1)<=e
fprintf('the root is %d% \n');
return
end
while abs(f1)>=e
x=x-(f1/f11);
f1=x.^3-10*x.^2+15*x+3;
f11=diff(x.^3-10*x.^2+15*x+3,x,1);
end
a=x;
end

and this is what is says after trying to run the code

>> a=search_root_3(x1,e)

a =

Empty matrix: 1-by-0


and i am asking YYYY?!
i will be gald for some help
thank u all
 

1. What is the Newton-Raphson method in Matlab?

The Newton-Raphson method in Matlab is a numerical method for finding the root of a nonlinear equation. It involves using an initial guess and iteratively refining it using the formula: xn+1 = xn - f(xn)/f'(xn), where f(x) is the function and f'(x) is its derivative.

2. How does the Newton-Raphson method work?

The Newton-Raphson method works by using an initial guess and iteratively refining it until the value of the function at that point is close to zero. This is done by finding the tangent line at the initial guess and seeing where it intersects with the x-axis. The x-coordinate of this intersection becomes the next guess, and the process is repeated until the desired level of accuracy is achieved.

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

One advantage of using the Newton-Raphson method in Matlab is that it is a fast and efficient method for finding the root of a nonlinear equation. It also allows for a high level of accuracy, as the process can be repeated until the desired level of precision is achieved. Additionally, the method is relatively simple to implement in Matlab.

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

One limitation of the Newton-Raphson method in Matlab is that it may not always converge to the desired root. This can happen when the initial guess is too far from the actual root, or when the function has multiple roots. Additionally, the method can be computationally intensive, especially for complex functions.

5. How can the Newton-Raphson method be used to solve real-world problems?

The Newton-Raphson method can be used to solve real-world problems by formulating the problem as a nonlinear equation and then using the method to find the root. This can be useful in many fields, such as engineering, economics, and physics, where nonlinear equations are commonly encountered. The method can also be used to solve optimization problems by finding the root of the derivative of the objective function.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
569
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
126
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
Back
Top