What are the 3 Newton-Raphson formulas to solve a system of three nonlinear equations in Matlab?
This is the code for Newton raphson method for three variable
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
The output of the program will be
iter=1.000000000000000, c=0.000000000389029, s=0.015000000287216, q=0.979999999955780
iter=2.000000000000000, c=0.000000001356998, s=0.158028331191731, q=0.923765241962920
iter=3.000000000000000, c=0.000000001181617, s=0.104156261426515, q=0.952886937302707
iter=4.000000000000000, c=0.000000001216663, s=0.085849634576983, q=0.958360887077671
iter=5.000000000000000, c=0.000000001224388, s=0.084367460093642, q=0.958463129596494
iter=6.000000000000000, c=0.000000001224423, s=0.084367992582976, q=0.958463625488450
Get Answers For Free
Most questions answered within 1 hours.