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

In summary, the conversation is about using the Newton-Raphson method in Matlab to solve a system of three non-linear equations with three variables. The equations involve parameters such as $I, k_f, k_d, k_n, k_p, \lambda_b, \lambda_r, \gamma, \alpha, P_C,$ and $P_Q$. The goal is to find the values for $c, s,$ and $q$ that satisfy the equations and converge to a tolerance of $10^{-4}$. The conversation includes defining the equations,
  • #1
ra_forever8
129
0
I am trying to solve 3 non-linear system of 3 variables using the Newton-raphson method in matlab. Here are the three 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}
Solve the above systems of equation to get the values for $c,s$ and $q$? $tolerence= 10^{-4}$. initail values:$ (c_0,s_0,q_0)=0$.
The values for the parameters are:
$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}$=>
This is what I think to do in matlab, but i don't know how to start the code in matlab. I have define the function for 3 systems of equation.\begin{equation} f(c,s,q)=> c[\alpha I+ k_f+k_d+k_ns+k_p(1-q)]-I \alpha =0 \end{equation}
\begin{equation} g(c,s,q)=>s[\lambda_b c P_C +\lambda_r (1-q)]- \lambda_b c P_C =0 \end{equation}
\begin{equation} h(c,s,q)=>q[\gamma +c k_p \frac{P_C}{P_Q}]- c k_p \frac{P_C}{P_Q}=0 \end{equation}now, i have to do partial derivatives of $f(c,s,q), g(c,s,q), h(c,s,q)$ in terms of $c, s, q$.Then set up the matrix $J$ and do the inverse matrix ($J^{-1}$). And apply the netwon iteration method, using $(c,s,q)= (c_0,s_0,q_0) - J^{-1} (f,g,h)$.I need to do some iterations until it converges to $tolerence= 10^{-4}$.Can please help me how to do in MATLAB with the MATLAB code. I am beginner in matlab.
 
Physics news on Phys.org
  • #2
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.

=>
can someone please check my code, there are no errors. did I got correct values for c,s and q? Thanks in advance.
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
 
Last edited:

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

1. What is the Newton-Raphson method for solving non-linear systems of 3 variables in Matlab?

The Newton-Raphson method is an iterative numerical method used to solve a system of non-linear equations. In Matlab, it can be used to find the roots of a system of 3 equations with 3 unknown variables. It is based on the idea of approximating the solution by a linear function and then using the slope of this function to update the guess for the solution until a desired level of accuracy is achieved.

2. How does the Newton-Raphson method work in Matlab?

In Matlab, the Newton-Raphson method works by taking an initial guess for the solution of the system of equations. It then uses this guess to calculate the corresponding Jacobian matrix, which contains the partial derivatives of each equation with respect to each variable. The Jacobian matrix is then used to update the guess for the solution, and this process is repeated until a desired level of accuracy is achieved.

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

One of the main advantages of using the Newton-Raphson method in Matlab is its fast convergence rate. It can quickly find the solution of a non-linear system of equations with high accuracy. Additionally, it can handle systems with multiple equations and unknowns, making it a versatile method for solving various types of problems.

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

The Newton-Raphson method can only find a solution if an initial guess is provided. If the guess is not close enough to the actual solution, the method may fail to converge. Additionally, it may not work for systems with singular or ill-conditioned Jacobian matrices. In some cases, it may also converge to a local minimum instead of the global minimum.

5. How can I use the Newton-Raphson method in Matlab for a non-linear system of 3 variables?

To use the Newton-Raphson method in Matlab for a non-linear system of 3 variables, you can define the system of equations as a function with the variables as inputs. Then, you can use the fsolve function, which implements the Newton-Raphson method, to find the solution. You will need to provide an initial guess for the solution, as well as the fsolve options for desired accuracy and maximum number of iterations.

Back
Top