Iterative evaluation of symbolic Jacobian matrix for multiple variable values for Newton Raphson model for nonlinear system of equation.
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello everyone,
I am doing actually a very simple work, yet somewhat I cannot get the desired result, any help and guidance will be appriciated in advance.
So, the problem is that I have a 6 node electrical network, and I am trying to find the unknown voltages by using Newton Raphson iterative method. I have obtained the Jacobian matrix and everything seems quite easy, the only problematic part is that I cannot evaluate the Jacobian matrix and the initial set of nonliear equations for the array of variable values in an iterative fashion.
I used 'subs' to evaluate the matices yet, they do not update after the first iteration.
I will attach the code below to clarify myself. Very much thankful for your time and help in advance.
clc, clear
syms u1 u2 u3 u4
F1 = 0.5*u1^2 - 0.5*u1*u3 + 5.7e6;
F2 = 0.625*u2^2 - 0.625*u2*u4 + 4.8e6;
F3 = -0.5*u1*u3 + 2.75*u3^2 - 1.25*u3*u4 - 20e3*u3;
F4 = -0.625*u2*u4 - 1.25*u3*u4 + 2.675*u4^2 - 16e3*u4;
F = [F1; F2; F3; F4];
JF = jacobian([F1, F2, F3, F4], [u1, u2, u3, u4]);
ig = num2cell([15e3,15e3,15e3,15e3]); %initial guess
[u1, u2, u3, u4] = deal(ig{:});
Un = [u1; u2; u3; u4];
tol = 1e-3; % error
Err = [10; 10; 10; 10]; % initial given error
nit = 0; % number of iterations
while max(Err, [], 'all') > tol && nit < 5 %fixed point iteration loop
%I want to update the the iterations with new input variable values as below, but does not work
Un1 = Un - subs(JF)\subs(F); %NR formula to update next set of variables
Err = abs(Un1 - Un)
Un = Un1
nit = nit+1 %iteration countere
end
0 Commenti
Risposta accettata
Matt J
il 6 Ott 2021
Modificato: Matt J
il 6 Ott 2021
syms u1 u2 u3 u4
F1 = 0.5*u1^2 - 0.5*u1*u3 + 5.7e6;
F2 = 0.625*u2^2 - 0.625*u2*u4 + 4.8e6;
F3 = -0.5*u1*u3 + 2.75*u3^2 - 1.25*u3*u4 - 20e3*u3;
F4 = -0.625*u2*u4 - 1.25*u3*u4 + 2.675*u4^2 - 16e3*u4;
F = matlabFunction( [F1; F2; F3; F4]);
JF = matlabFunction( jacobian([F1, F2, F3, F4], [u1, u2, u3, u4]));
F=@(u)F(u(1),u(2),u(3),u(4));
JF=@(u)JF(u(1),u(2),u(3),u(4));
Un = [15e3,15e3,15e3,15e3].';
tol = 1e-3; % error
Err=inf;
nit = 0; % number of iterations
while max(Err, [], 'all') > tol && nit < 5 %fixed point iteration loop
%I want to update the the iterations with new input variable values as below, but does not work
Un1 = Un - JF(Un)\F(Un); %NR formula to update next set of variables
Err = abs(Un1 - Un);
Un = Un1;
nit = nit+1 %iteration countere
end
ErrF=norm(F(Un1),inf)
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Symbolic Math Toolbox in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!