how to Solve 4 Equation and 3 unknown
6 次查看(过去 30 天)
显示 更早的评论
syms T1 T2 alpha
E1 = (wg*( T1 + T2*alpha ) / ( 1 - alpha*wg^2*T1*T2 )) == A1;
E2 = (wg*( alpha*T1 + T2 ) / ( 1 - alpha*wg^2*T1*T2 )) == B1;
E3 = (wp*( T1 + T2*alpha ) / ( 1 - alpha*wp^2*T1*T2 )) == A2;
E4 = (wp*( alpha*T1 + T2 ) / ( 1 - alpha*wp^2*T1*T2 )) == B2;
S1 = solve([E1,E2,E3,E4],T1,T2,alpha);
Where A1 ,A2,B1, B2,wg and wp are constant
0 个评论
采纳的回答
Bjorn Gustavsson
2021-10-13
When you have four non-linear equations with three unknowns you cannot, in general, expect to get a symbolic solution. For these types of problems you will have to resort to some kind of minimization/optimization approach. The first stab to try is typically to do a least-squares minimization of the square of the residuals - if there happens to be one exact solution that will also be a valid solution of the four original equations, if there is some global minima then that is as good as you can do. For this write a function for the square of the residuals, something like this:
function err = you4nonlsqerrfcn(pars,A1,B1,A2,B2,wg,wp)
T1 = pars(1);
T2 = pars(2);
alpha = pars(3);
E1 = (wg*( T1 + T2*alpha ) / ( 1 - alpha*wg^2*T1*T2 )) - A1;
E2 = (wg*( alpha*T1 + T2 ) / ( 1 - alpha*wg^2*T1*T2 )) - B1;
E3 = (wp*( T1 + T2*alpha ) / ( 1 - alpha*wp^2*T1*T2 )) - A2;
E4 = (wp*( alpha*T1 + T2 ) / ( 1 - alpha*wp^2*T1*T2 )) - B2;
err = sum([E1,E2,E3,E4].^2);
end
Then you make a start-guess and try the fminsearch-function:
T1T2alpha0 = [1 2 pi/3];
[T1T2alpha1,Fval,ExFlag] = fminsearch(@(pars) you4nonlsqerrfcn(pars,A1,B1,A2,B2,wg,wp),T1T2alpha0);
If Fval is close enough to zero and ExFlag is 1 you ought to have an acceptable solution, if not you might have to continue the search from T1T2alpha1 or try a new start-guess.
Once you've done this you can also make an attempt to use lsqnonlin with a modified version of the error-function that instead of returning the sum-of-squared of the residuals returns the residuals directly (i.e. E1, E2, E3 and E4). This might be numerically more efficient.
HTH
2 个评论
Bjorn Gustavsson
2021-10-13
When I defined the function just as above and saved it in a file you4nonlsqerrfcn.m and then rand the following commands at the command-line:
A1 = 1;
A2 = 1.5;
B1 = 1/2;
B2 = 1/3;
wg = pi/5;
wp = exp(0.5);
T1T2alpha0 = [1 2 pi/3];
[T1T2alpha1,Fval,ExFlag] = fminsearch(@(pars) you4nonlsqerrfcn(pars,A1,B1,A2,B2,wg,wp),T1T2alpha0)
T1T2alpha1 =
1.0481 1.0481 0.99999
Fval =
19.888
ExFlag =
1
So that works that far. It is difficult to know what is causing your problem...
HTH
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Assumptions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!