The detailed process of Newton iteration method used in Dymola - modelica
In dymola, when debugging the nonlinear equation set, there is some information about the solving process like the following, I could see that it is using Newton iteration method, but I don't understand every detail. So I am looking for some material online to show the detailed process about Newton method used in dymola, could anyone give me a recommendation?
singularPressureLoss3.C1.h_vol = 208022
singularPressureLoss3.C2.h_vol = 208022
CondensatePump.h = 207466
singularPressureLoss3.Pm = 811678
singularPressureLoss2.Pm = 811678
nTUWaterHeating1.Ee.P = 1.96559E+06
CondensatePump.Qv = 0.28517
nTUWaterHeating3.Se.h_vol = 380000
nTUWaterHeating1.Ee.h_vol = 380000
nTUWaterHeating1.Se.h_vol = 515000
Dp_Cond_5.Pm = 2.303E+06
CondensatePump1.C2.h_vol = 150161
Drum_2.Cs2.h = 740000
nTUWaterHeating4.HDesF = 621664
nTUWaterHeating4.HeiF = 520603
CondensatePump1.Qv = 0.321957
nTUWaterHeating4.Hep = 654967
nTUWaterHeating4.h = 402000
Drum_2.h = 713039
VolumeCond5.h = 3.154E+06
Condenser.prod.d = 988.273
nTUWaterHeating3.promeF.d = 978.574
nTUWaterHeating1.promeF.d = 953.838
nTUWaterHeating2.promeF.d = 929.357
CondensatePump.pro.d = 988.642
CondensatePump1.pro.d = 903.437
Residual:
{ 2.30783E+06, -0, -0, -2.30783E+06, 0,
-0, -1.15374E+06, 2.91038E-11, -2.91038E-11, 7.84689E+06,
0, 0, -26960.5, -622211, -322636,
-2.93613E+07, 18180, 7.32352E+07, -2983.59, -6000,
0, 1001.68, -0.700874, -0.772015, -0.0825135,
5.4358 }
Jacobian element(1 singularPressureLoss3.C1.h_vol,2)= is 0 [analytic] or -1 [sum=0]
Jacobian element(1 singularPressureLoss3.C1.h_vol,8)= is 0 [analytic] or -2 [sum=0]
Jacobian element(1 singularPressureLoss3.C1.h_vol,9)= is 0 [analytic] or 1 [sum=0]
Jacobian element(1 singularPressureLoss3.C1.h_vol,21)= is 0 [analytic] or -0.000107159 [sum=0]
Jacobian element(1 singularPressureLoss3.C1.h_vol,22)= is 0 [analytic] or -3.92884e-05 [sum=0]
Jacobian element(2 singularPressureLoss3.C2.h_vol,2)= is 0 [analytic] or 1 [sum=0]
Jacobian element(3 CondensatePump.h,8)= is 0 [analytic] or 2 [sum=0]
Jacobian element(3 CondensatePump.h,9)= is 0 [analytic] or -2 [sum=0]
Jacobian element(3 CondensatePump.h,21)= is 0 [analytic] or 0.000214318 [sum=0]
Jacobian element(3 CondensatePump.h,25)= is 0 [analytic] or 0.000107132 [sum=0]
Jacobian element(4 singularPressureLoss3.Pm,1)= is 0 [analytic] or 2 [sum=0]
Jacobian element(4 singularPressureLoss3.Pm,7)= is 0 [analytic] or -2 [sum=0]
Jacobian element(4 singularPressureLoss3.Pm,25)= is 0 [analytic] or -5.27295e-07 [sum=0]
Jacobian element(5 singularPressureLoss2.Pm,1)= is 0 [analytic] or -4 [sum=0]
Jacobian element(5 singularPressureLoss2.Pm,4)= is 0 [analytic] or 2 [sum=0]
Jacobian element(5 singularPressureLoss2.Pm,7)= is 0 [analytic] or 2 [sum=0]
Jacobian element(5 singularPressureLoss2.Pm,22)= is 0 [analytic] or -0.000135014 [sum=0]
Jacobian element(5 singularPressureLoss2.Pm,25)= is 0 [analytic] or 5.27304e-07 [sum=0]
Jacobian element(6 nTUWaterHeating1.Ee.P,1)= is 0 [analytic] or 2 [sum=0]
Jacobian element(6 nTUWaterHeating1.Ee.P,4)= is 0 [analytic] or -2 [sum=0]
Jacobian element(6 nTUWaterHeating1.Ee.P,7)= is 0 [analytic] or -1 [sum=0]
Jacobian element(6 nTUWaterHeating1.Ee.P,19)= is 0 [analytic] or 3.53142e-05 [sum=0]
Jacobian element(6 nTUWaterHeating1.Ee.P,22)= is 0 [analytic] or 6.75072e-05 [sum=0]
Jacobian element(6 nTUWaterHeating1.Ee.P,23)= is 0 [analytic] or -6.06325e-07 [sum=0]
Jacobian element(6 nTUWaterHeating1.Ee.P,24)= is 0 [analytic] or -6.67641e-07 [sum=0]
Jacobian element(6 nTUWaterHeating1.Ee.P,25)= is 0 [analytic] or -2.63641e-07 [sum=0]
Jacobian element(6 nTUWaterHeating1.Ee.P,26)= is 0 [analytic] or -7.46357e-07 [sum=0]
Jacobian element(7 CondensatePump.Qv,1)= is 0 [analytic] or -0.0625 [sum=0]
Jacobian element(7 CondensatePump.Qv,4)= is 0 [analytic] or -0.0625 [sum=0]
Jacobian element(7 CondensatePump.Qv,8)= is 0 [analytic] or -2264.25 [sum=0]
Jacobian element(7 CondensatePump.Qv,10)= is 0 [analytic] or 7.70543e+07 [sum=0]
Jacobian element(7 CondensatePump.Qv,16)= is 0 [analytic] or 5.34118e+08 [sum=0]
Jacobian element(7 CondensatePump.Qv,17)= is 0 [analytic] or 2.84024e+08 [sum=0]
Jacobian element(7 CondensatePump.Qv,18)= is 0 [analytic] or 5.74129e+07 [sum=0]
Jacobian element(7 CondensatePump.Qv,19)= is 0 [analytic] or -4.66146e+07 [sum=0]
Jacobian element(8 nTUWaterHeating3.Se.h_vol,5)= is 0 [analytic] or -1 [sum=0]
Jacobian element(9 nTUWaterHeating1.Ee.h_vol,3)= is 0 [analytic] or 1 [sum=0]
Jacobian element(10 nTUWaterHeating1.Se.h_vol,6)= is 0 [analytic] or 1 [sum=0]
Jacobian element(11 Dp_Cond_5.Pm,16)= is 0 [analytic] or 0.0132414 [sum=0]
Jacobian element(11 Dp_Cond_5.Pm,17)= is 0 [analytic] or 0.0132414 [sum=0]
Jacobian element(11 Dp_Cond_5.Pm,19)= is 0 [analytic] or -6.47926e-05 [sum=0]
Jacobian element(11 Dp_Cond_5.Pm,20)= is 0 [analytic] or -2 [sum=0]
Jacobian element(12 CondensatePump1.C2.h_vol,14)= is 0 [analytic] or 1 [sum=0]
Jacobian element(13 Drum_2.Cs2.h,10)= is 0 [analytic] or 290.868 [sum=0]
Jacobian element(13 Drum_2.Cs2.h,13)= is 0 [analytic] or -1 [sum=0]
Jacobian element(13 Drum_2.Cs2.h,14)= is 0 [analytic] or -1 [sum=0]
Jacobian element(13 Drum_2.Cs2.h,18)= is 0 [analytic] or 290.868 [sum=0]
Jacobian element(13 Drum_2.Cs2.h,19)= is 0 [analytic] or -0.0636731 [sum=0]
Jacobian element(13 Drum_2.Cs2.h,26)= is 0 [analytic] or 0.000235521 [sum=0]
Jacobian element(14 nTUWaterHeating4.HDesF,15)= is 0 [analytic] or 1 [sum=0]
Jacobian element(14 nTUWaterHeating4.HDesF,16)= is 0 [analytic] or -290.868 [sum=0]
Jacobian element(15 nTUWaterHeating4.HeiF,16)= is 0 [analytic] or 290.868 [sum=0]
Jacobian element(15 nTUWaterHeating4.HeiF,18)= is 0 [analytic] or -290.868 [sum=0]
Jacobian element(16 CondensatePump1.Qv,12)= is 0 [analytic] or -903.437 [sum=0]
Jacobian element(16 CondensatePump1.Qv,14)= is 0 [analytic] or 50001.4 [sum=0]
Jacobian element(16 CondensatePump1.Qv,18)= is 0 [analytic] or -1.45438e+07 [sum=0]
Jacobian element(16 CondensatePump1.Qv,19)= is 0 [analytic] or 3183.75 [sum=0]
Jacobian element(16 CondensatePump1.Qv,26)= is 0 [analytic] or -5.88818 [sum=0]
Jacobian element(17 nTUWaterHeating4.Hep,17)= is 0 [analytic] or -0.0632785 [sum=0]
Jacobian element(17 nTUWaterHeating4.Hep,18)= is 0 [analytic] or -0.063278 [sum=0]
Jacobian element(17 nTUWaterHeating4.Hep,19)= is 0 [analytic] or -0.000239221 [sum=0]
Jacobian element(18 nTUWaterHeating4.h,16)= is 0 [analytic] or -0.0632792 [sum=0]
Jacobian element(19 Drum_2.h,10)= is 0 [analytic] or 0.0632784 [sum=0]
Jacobian element(19 Drum_2.h,13)= is 0 [analytic] or 1 [sum=0]
Jacobian element(19 Drum_2.h,18)= is 0 [analytic] or 0.0632784 [sum=0]
Jacobian element(19 Drum_2.h,19)= is 0 [analytic] or 0.0627446 [sum=0]
Jacobian element(20 VolumeCond5.h,10)= is 0 [analytic] or -9 [sum=0]
Jacobian element(20 VolumeCond5.h,11)= is 0 [analytic] or 290.8 [sum=0]
Jacobian element(21 Condenser.prod.d,7)= is 0 [analytic] or 14.71 [sum=0]
Jacobian element(21 Condenser.prod.d,21)= is 0 [analytic] or 0.999992 [sum=0]
Jacobian element(21 Condenser.prod.d,25)= is 0 [analytic] or -3.8835e-06 [sum=0]
Jacobian element(22 nTUWaterHeating3.promeF.d,22)= is 0 [analytic] or 1 [sum=0]
Jacobian element(23 nTUWaterHeating1.promeF.d,23)= is 0 [analytic] or 1 [sum=0]
Jacobian element(24 nTUWaterHeating2.promeF.d,24)= is 0 [analytic] or 1 [sum=0]
Jacobian element(25 CondensatePump.pro.d,1)= is 0 [analytic] or -3.13126e-05 [sum=0]
Jacobian element(25 CondensatePump.pro.d,4)= is 0 [analytic] or -3.13126e-05 [sum=0]
Jacobian element(25 CondensatePump.pro.d,7)= is 0 [analytic] or 794.339 [sum=0]
Jacobian element(25 CondensatePump.pro.d,10)= is 0 [analytic] or 22226 [sum=0]
Jacobian element(25 CondensatePump.pro.d,16)= is 0 [analytic] or 154064 [sum=0]
Jacobian element(25 CondensatePump.pro.d,17)= is 0 [analytic] or 81925.8 [sum=0]
Jacobian element(25 CondensatePump.pro.d,18)= is 0 [analytic] or 16560.5 [sum=0]
Jacobian element(25 CondensatePump.pro.d,19)= is 0 [analytic] or -13445.8 [sum=0]
Jacobian element(25 CondensatePump.pro.d,25)= is 0 [analytic] or 1 [sum=0]
Jacobian element(26 CondensatePump1.pro.d,12)= is 0 [analytic] or -0.321957 [sum=0]
Jacobian element(26 CondensatePump1.pro.d,19)= is 0 [analytic] or 0.87266 [sum=0]
Jacobian element(26 CondensatePump1.pro.d,26)= is 0 [analytic] or 0.990778 [sum=0]
Residual scale row 1, J_sum=9.60125e+06
Residual scale row 2, J_sum=416046
Residual scale row 3, J_sum=380001
Residual scale row 4, J_sum=5.95454e+06
Residual scale row 5, J_sum=380001
Residual scale row 6, J_sum=515001
Residual scale row 7, J_sum=7.31959e+06
Residual scale row 8, J_sum=833890
Residual scale row 9, J_sum=622957
Residual scale row 10, J_sum=3.86857e+08
Residual scale row 11, J_sum=9.17183e+08
Residual scale row 12, J_sum=1806.49
Residual scale row 13, J_sum=1.45304e+06
Residual scale row 14, J_sum=956263
Residual scale row 15, J_sum=621665
Residual scale row 16, J_sum=1.32481e+09
Residual scale row 17, J_sum=5.2785e+08
Residual scale row 18, J_sum=4.92668e+08
Residual scale row 19, J_sum=8.67177e+07
Residual scale row 20, J_sum=4.806e+06
Residual scale row 21, J_sum=2053.01
Residual scale row 22, J_sum=2247.28
Residual scale row 23, J_sum=1953.09
Residual scale row 24, J_sum=1928.74
Residual scale row 25, J_sum=2010.38
Residual scale row 26, J_sum=2067.51
The non-linear system is difficult to solve, this could either be
due to a dependency between equations, or due to bad start-values.
Variable 17(nTUWaterHeating4.Hep)=654967 has small pivot 8.67901e-11 and is hard to solve,
Variable 18(nTUWaterHeating4.h)=402000 has small pivot 3.89036e-11 and is hard to solve.
Condition estimate of Jacobian matrix 22908577406.43897
Expression nTUWaterHeating4.Ev.Q > 0 became true ( (nTUWaterHeating4.Ev.Q)-(0) = 4.93669 )
Expression Drum_2.Ce1.Q > 0 became true ( (Drum_2.Ce1.Q)-(0) = 4.93669 )
Error: The following error was detected at time: 0
Water_Ph: Incorrect region number (-1)
Failed condition: false
If you can generate C-Code from your Dymola model (provided you have a SourCodeExport license) you can view the details of the implementation and reference to literature in the code by inspecting dsmodel.c
If you do not have a license, you can inspect the code by looking ot dsmodel.c in one of the provided source code FMUs from Dassault in the FMI Cross-Check, see e.g. https://github.com/modelica/fmi-cross-check/blob/master/fmus/2.0/me/c-code/Dymola/2019FD01/Engine1b/Engine1b.fmu (the FMU is a zip-File, see ./sources/dsmodel.c)
Related
quiver3 returns vectors with incorrect length
I have a set of vectors t = [ -1 -1 0 1 -1 0 1 1 0 -1 1 0 ] those vectors form a square when plotted sequentially (head to tail) I am using the quiver3 instruction to obtain a plot of those vectors as follows: quiver3(starts(:,1), starts(:,2), starts(:,3), t(:,1), t(:,2), t(:,3)) I calculated "starts" by cumulative sums of the matrix t and got the following result starts = [ 0 0 0 -1 -1 0 0 -2 0 1 -1 0] All the values makes perfect sense and would give a square if plotted manually, but quiver3 returned the following plot Why aren't the vectors' heads touching the tails? how can I fix that?
You need to set the AutoScaleFactor to 1: t = [... -1 -1 0 1 -1 0 1 1 0 -1 1 0] starts = [... 0 0 0 -1 -1 0 0 -2 0 1 -1 0] quiver3(starts(:,1), starts(:,2), starts(:,3), t(:,1), t(:,2), t(:,3), ... 'AutoScaleFactor',1) It is set to 0.9 by default as a whole vector field would look a little messy otherwise. Edit: see how this works for you: starts = [ 0 0 0; -13 12 0] t = [ -13 12 0; -1 2 0] quiver3(starts(:,1), starts(:,2), starts(:,3), t(:,1), t(:,2), t(:,3), 0) view(0,90) The 0 defines the fixed scale factor, 0 means no scaling.
Roots of transcendental equation formed from determinant of a matrix containing bessel functions in Matlab
I need to find roots of a transcendental equation formed by taking determinant of the following matrix. As you can see it is full of Bessel functions. I tired using the "fzero" command but it is not working. All the bessel function inputs such as gamma and eta are function of beta. A= [besselj(0,gamma1) -besselj(0,eta1*a/b) -bessely(0,eta1*a/b) 0 0 0 0; K1*besselj(1,gamma1) -besselj(1,eta1*a/b) -bessely(1,eta1*a/b) 0 0 0 0; 0 besselj(0,eta1) bessely(0,eta1) -besselj(0,gamma2) -bessely(0,gamma2) 0 0; 0 K2*besselj(1,eta1) K2*bessely(1,eta1) -besselj(1,gamma2) -bessely(1,gamma2) 0 0; 0 0 0 besselj(0,gamma2*c/b) bessely(0,gamma2*c/b) -besselj(0,eta2) -bessely(0, eta2); 0 0 0 K3*besselj(1,gamma2*c/b) K3*bessely(1,gamma2*c/b) -besselj(1,eta2) -bessely(1,eta2); 0 0 0 0 0 besselj(1,eta2*d/c)-H*besselj(0,eta2*d/c), bessely(1,eta2*d/c)-H*bessely(0,eta2*d/c);]; Please let me know how to find value roots of thie subject transcendetal equation. Thanks
How the eigen vector changed to identity matrix in kpca steps?
[eigvec eigval] = eigs(K_center,[],neigs,'lm',opts); disp('***********Eigen value(1)***************') disp(eigval) eig_val = eigval ~= 0; disp('***********Eigen value(2)***************') disp(eig_val) Output: ***********Eigen value(1)*************** 4.0001 0 0 0 1.0000 0 0 0 1.0000 ***********Eigen value(2)*************** 1 0 0 0 1 0 0 0 1 The eigen values returned are shown in Eigen value(1)...but after setting eigenvalues ~= 0 ...I get an identity matrix as shown in eigen value(2)..How has it changed to be an identity matrix and why ? I am refering http://www.mathworks.com/matlabcentral/fileexchange/27319-kernel- pca/content/kernelpca_tutorial.m Any help appreciated..Thanx in advance..
Proof of eigenvector and eigenvalues Matlab
I am finding the eigenvector and eigenvalues of a matrix, then I need to prove that Ax= λx where λ is the eigenvalue. Here is my code: A = [1 1 -1;1 0 -2; 0 0 -1] [evecs,evals]=eig(A) for i = 1:3 A*evecs(:,i)== evals(i,i)*evecs(:,i) end Here is my output: A = 1 1 -1 1 0 -2 0 0 -1 evecs = 0.8507 -0.5257 -0.3015 0.5257 0.8507 0.9045 0 0 0.3015 evals = 1.6180 0 0 0 -0.6180 0 0 0 -1.0000 ans = 0 0 1 ans = 0 1 1 ans = 0 0 1 Why are the ans not all equal to 1 as it should (in order to prove Ax= λx)
The calculations of your eigen solver are performed using finite precision floating point arithmetic. The true eigen values and eigen vectors are not even exactly representable in finite floating point data types. Check for equality against a small tolerance to allow for this. That is check that Ax - λx is small in absolute value. Required reading is What Every Computer Scientist Should Know About Floating-Point Arithmetic.
Solving matrices of the form Ax = B ==> error: Matrix is close to singular or badly scaled
I'm having trouble solving a system of the form Ax=B The solution to the system should be x = inv(A)*B However, this doesn't work. I get the following error message when I try the above line of code: Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 1.156482e-018. It seems that matlab is having trouble inverting the matrix that I've specified. I tried to verify that the inverse function was working properly by typing in inv(A)*A This should give the identity matrix, however I got the same error and some garbage numbers. This is the A matrix that I'm using: A = [5/2 1/2 -1 0 0 -1/2 -1/2 0 0 1/2 1/2 0 0 0 -1/2 -1/2 0 0 -1 0 5/2 -1/2 -1 0 0 -1/2 1/2 0 0 -1/2 1/2 0 0 0 1/2 -1/2 0 0 -1 0 3/2 -1/2 1/2 0 0 -1/2 -1/2 0 0 -1/2 2 0 -1 0 -1/2 -1/2 0 0 1/2 0 1 0 0 0 0 -1/2 1/2 0 -1 0 2 0 0 0 1/2 -1/2 0 0 0 0 1] Any ideas as to why this isn't working? I also tried to convert A to a sparse matrix (sparse(A)), and then run the inverse command. No dice.
The problem is indeed in your mathematics. The matrix you provided isn't of full rank, so it isn't invertible. You could verify that manually (haven't taken the time to do so), but MATLAB already points this out by showing that warning. Since you are working with floating point numbers, this sometimes causes other subtle problems, one of which you can see in the result of det(A), which is in the order of 1e-16, i.e. machine precision or 0 in practice. You can see that this Matrix is not of full rank by executing the rank function: rank(A) = 8. For a 9x9 matrix, this indeed means that the matrix is not invertible for doubles (as the rank function accounts for machine precision). If you want to use MATLAB to get a result that corresponds to a manual calculation, you can use the Symbolic Toolbox and its vpa (variable precision arithmetic) to work around possible numerical problems at the cost of a slower calculation. B = [5 1 -2 0 0 -1 -1 0 0; 1 1 0 0 0 -1 -1 0 0; -2 0 5 -1 -2 0 0 -1 1; 0 0 -1 1 0 0 0 1 -1; 0 0 -2 0 3 -1 1 0 0; -1 -1 0 0 -1 4 0 -2 0; -1 -1 0 0 1 0 2 0 0; 0 0 -1 1 0 -2 0 4 0; 0 0 1 -1 0 0 0 0 2]; A = B/2; size(A) % = [9 9] det(A) % = -1.38777878078145e-17 rank(A) % = 8 C = vpa(A); det(C) % = 0.0 rank(C) % = 8 Both with VPA and floating points you will get that the rank is 8, the size is [9 9] and the determinant is practically 0, i.e. singular or not invertible. Changing a few entries might make your matrix regular (non-singular), but it is not guaranteed to work and it will solve a different problem. To solve your actual problem A*x=b for x, you can try to use mldivide (a.k.a. the backslash operator) or a Moore-Penrose pseudo-inverse: x1 = A\b; x2 = pinv(A)*b; But do remember that such a system does not have a unique solution, so both the pseudo-inverse and the backslash operator may (and in this case will) return very different solutions, whether any of them is acceptable really depends on your application.
It means exactly what it says. The matrix is singular, which means it can't really be inverted. Not all matrices can. In geometrical terms, you have a matrix that transforms one 9-dimensional object into another, but flattens one dimension out completely. That can't be undone; there's no way to tell how far to pull things out in that direction.
The matrix is singular, consider B=2*A below: B = [5 1 -2 0 0 -1 -1 0 0; 1 1 0 0 0 -1 -1 0 0; -2 0 5 -1 -2 0 0 -1 1; 0 0 -1 1 0 0 0 1 -1; 0 0 -2 0 3 -1 1 0 0; -1 -1 0 0 -1 4 0 -2 0; -1 -1 0 0 1 0 2 0 0; 0 0 -1 1 0 -2 0 4 0; 0 0 1 -1 0 0 0 0 2] det(B) 0
bicgstab(A,b,tol,maxit), an iterative solver, was able to solve a singular linear system A*x=b for a singular matrix A: size(A)=[162, 162] rank(A)=14 cond(A)=4.1813e+132 I used: tol=1e-10; maxit=100; None of the above-mentioned (including svd, \, inv, pinv, gmres) worked for me but bicgstab did a good job. bicgstab converged at iteration 4 to a solution with relative residual 1.1e-11. It works fast for sparse matrices. See documentation here: https://uk.mathworks.com/help/matlab/ref/bicgstab.html