how to Solve 4 Equation and 3 unknown

6 vues (au cours des 30 derniers jours)
RJS
RJS le 12 Oct 2021
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

Réponse acceptée

Bjorn Gustavsson
Bjorn Gustavsson le 13 Oct 2021
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 commentaires
RJS
RJS le 13 Oct 2021
getting this error
>> equation
Not enough input arguments.
Error in equation (line 2)
T1 = pars(1);
>> equation
Error: File: equation.m Line: 11 Column: 1
This statement is not inside any function.
(It follows the END that terminates the definition of the function "you4nonlsqerrfcn".)
Bjorn Gustavsson
Bjorn Gustavsson le 13 Oct 2021
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

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by