Newton-Raphson Method for Non-linear System of 3 variables in Matlab

In summary, the conversation discusses using the Newton-Raphson method in MATLAB to solve a system of three non-linear equations with three variables. The code provided includes values for the parameters and an initial guess for the variables, as well as functions and partial derivatives for each variable. The Jacobian matrix is also calculated and used in the Newton-Raphson method to iteratively update the values of c, s, and q until a convergence tolerance is reached. The accuracy of the final values is uncertain without further analysis of the code.
  • #1
wel
Gold Member
36
0
I am trying to solve 3 non-linear system of 3 variables using the Newton-raphson method in matlab. Here are the 3 non-linear equations:

\begin{equation} c[\alpha I+ k_f+k_d+k_ns+k_p(1-q)]-I \alpha =0 \end{equation}
\begin{equation} s[\lambda_b c P_C +\lambda_r (1-q)]- \lambda_b c P_C =0 \end{equation}
\begin{equation} q[\gamma +c k_p \frac{P_C}{P_Q}]- c k_p \frac{P_C}{P_Q}=0 \end{equation}

I need to find the values of c,s, and q using the Newton-raphson method.

=>
This is my MATLAB code :

Code:
 format long
    clear; 
  
 %values of parameters
    I=1200;
    k_f= 6.7*10.^7;
    k_d= 6.03*10.^8; 
    k_n=2.92*10.^9; 
    k_p=4.94*10.^9;
    lambda_b= 0.0087;
    lambda_r =835; 
    gamma =2.74; 
    alpha =1.14437*10.^-3;
    P_C= 3 * 10.^(11);
    P_Q= 2.87 * 10.^(10);    
tol = 10.^-4;  %tol is a converge tolerance    
%initial guess or values
  c=1; 
  s=0.015;
  q=0.98; 
  iter= 0; %iterations
  xnew =[c;s;q];
  xold = zeros(size(xnew));
  while norm(xnew - xold) > tol
      iter= iter + 1;
      xold = xnew;      % update c, s, and q
      c = xold(1);
      s = xold(2);
      q = xold(3);
      
%Defining the functions for c,s and q.
      f = c * (alpha*I + k_f + k_d + k_n * s + k_p*(1-q))-I *alpha;
      g = s * (lambda_b * c* P_C + lambda_r *(1-q))- lambda_b* c * P_C; 
      h = q * ( gamma + c * k_p *(P_C / P_Q))- (c * k_p * (P_C / P_Q));     

%Partial derivatives in terms of c,s and q.
      dfdc = alpha*I + k_f + k_d + k_n * s + k_p*(1-q);
      dfds = k_n *c ;
      dfdq = - k_p *c;      
      
      dgdc = lambda_b * P_C *(s-1);
      dgds = lambda_b * c* P_C + lambda_r *(1-q);
      dgdq = - lambda_r * s;      
      
      dhdc = k_p *(P_C / P_Q)*(q-1);
      dhds = 0;
      dhdq = gamma + c * k_p *(P_C / P_Q);     
      
       %Jacobian matrix 
      J = [dfdc dfds dfdq; dgdc dgds dgdq; dhdc dhds dhdq];    
      
      % Applying the Newton-Raphson method
      xnew = xold - J\[f;g;h];
      disp(sprintf('iter=%6.15f,  c=%6.15f,  s=%6.15f, q=%6.15f', iter,xnew)); 
  end
can someone please check my code, there are no errors but did i got accurate values of c,s, and q?. Thanks in advance.
 
Last edited:
Physics news on Phys.org
  • #2
I'm not a Matlab expert, and I didn't check your code in detail, but clearly your definition of the Jacobian is wrong.

You have: J = [dfdc dfds dfds; dgds dgds dgds; dhds dhds dhds];

You want: J = [dfdc dfds dfdq; dgdc dgds dgdq; dhdc dhds dhdq];
 
  • Like
Likes 1 person

What is the Newton-Raphson method for non-linear systems of 3 variables?

The Newton-Raphson method is an iterative numerical method used to find the roots of a system of non-linear equations. It is based on the idea of linearizing the equations around an initial guess and using the slope of the tangent line at that point to find a better approximation of the root.

How does the Newton-Raphson method work?

The Newton-Raphson method starts with an initial guess for the roots of the system of equations. Then, it uses the partial derivatives of the equations to construct a Jacobian matrix, which is used to linearize the equations. The method then iteratively updates the initial guess using the inverse of the Jacobian matrix until a desired level of accuracy is achieved.

What are the advantages of using the Newton-Raphson method?

The Newton-Raphson method is a very efficient and accurate method for solving non-linear systems of equations. It has a quadratic convergence rate, meaning that the number of correct digits in the approximation roughly doubles with each iteration. It also allows for finding multiple roots of the system simultaneously.

What are the limitations of the Newton-Raphson method?

The Newton-Raphson method may fail to converge if the initial guess is not close enough to the actual roots of the system. It also requires the computation of partial derivatives, which can be difficult for complex equations. Additionally, the method may fail if the Jacobian matrix is ill-conditioned.

How can the Newton-Raphson method be implemented in Matlab?

In Matlab, the Newton-Raphson method can be implemented using the "fsolve" function, which takes as input the system of equations, the initial guess, and an options structure with desired tolerances and maximum number of iterations. Alternatively, the method can be programmed using a loop that updates the initial guess based on the Jacobian matrix and the current approximation.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
9
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
Replies
1
Views
1K
Replies
1
Views
2K
  • Calculus and Beyond Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
21
Views
2K
Back
Top