Fitting 8 equations simultaneously with three parameters
43 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Vahid Askarpour
am 19 Sep. 2025 um 17:46
Kommentiert: Vahid Askarpour
am 19 Sep. 2025 um 21:08
I have 8 equations each with three parameters (A, B, and C) to be fitted. For example,
Eq. 1: 2A+3B+5C-1=0
Eq. 2: -5A+2B-10C+12=0 and so on
I would like to fit the three parameters so that all the 8 equations almost hold simultaneously. Having looked at other posts, it seems that lsqnonlin may be the right choice. I am not looking for the actual solution but I would appreciate a yes or no to the use of lsqnonlin for this problem.
Thanks,
Vahid
0 Kommentare
Akzeptierte Antwort
Torsten
am 19 Sep. 2025 um 17:49
Bearbeitet: Torsten
am 19 Sep. 2025 um 17:50
If all 8 equations are linear in the fitting parameters like in your example from above, "lsqlin" instead of "lsqnonlin" would be the code to use. If this is not the case, yes: use "lsqnonlin".
2 Kommentare
Torsten
am 19 Sep. 2025 um 19:40
Bearbeitet: Torsten
am 19 Sep. 2025 um 20:03
If there are no constraints on the solution parameters, @Star Strider 's suggestion is also possible to use:
% Eq. 1: 2A+3B+5C-1=0
% Eq. 2: -5A+2B-10C+12=0
% Eq. 3: 9A-B+2C+5=0
% Eq. 4: 4A-7B+6C-13=0
ABC = lsqlin([2 3 5; -5 2 -10; 9 -1 2; 4 -7 6],[1; -12; -5; 13])
ABC = [2 3 5; -5 2 -10; 9 -1 2; 4 -7 6] \ [1; -12; -5; 13]
Weitere Antworten (1)
Star Strider
am 19 Sep. 2025 um 18:11
Example --
% Eq. 1: 2A+3B+5C-1=0
% Eq. 2: -5A+2B-10C+12=0
% Eq. 3: 9A-B+2C+5=0 % <- ADDED
ABC = [2 3 5; -5 2 -10; 9 -1 2] \ [1; -12; -5]
fprintf('\nA = %9.5f\nB = %9.5f\nC = %9.5f\n',ABC)
.
Siehe auch
Kategorien
Mehr zu Linear Least Squares finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!