Symbolic Tool: Solve() returns the name of variables instead of expression or values.
3 ビュー (過去 30 日間)
古いコメントを表示
I was using symbolic toolbox to solve variables of nonlinear equations. solve() returns name of variables instead of either expression or values. I wonder anyone knows possible reasons and how to fix it. Besides, how symbolic tool to deal with the independence of a set of linear equations? any functions to check that? Thanks.
I paste the code as following.
-----------------------------------------------------------------
psi_1 = [2.98404798303315,4.03124553422975,5.07844308542635,5.07844308542635,0.889652880639957,2.98404798303316,0.889652880639950,4.03124553422976,0.889652880639957];
c = 3e8;
f = [1, 1.05, 1.10, 1, 1.05, 1.10, 1, 1.05, 1.10].*1e9;
lambda = c./f;
k = 2*pi./lambda;
[row_f, col_f] = size(f);
r_epsl = ones(3,2,1);
measure = ones(2,1);
factor1 = ones(1,2);
factor2 = ones(1,2);
factor = ones(2,2);
num_data = numel(f);
for i = 1:3:1
radar_obv1 = exp(j*psi_1(i+1)) / exp(j*psi_1(i));
radar_obv2 = exp(j*psi_1(i+2)) / exp(j*psi_1(i));
radar4_obv1 = exp(j*4*psi_1(i+1)) - exp(j*4*psi_1(i));
radar4_obv2 = exp(j*4*psi_1(i+2)) - exp(j*4*psi_1(i));
syms psi_t0 psi_t1 psi_t2 zeta_t0 zeta_t1 zeta_t2 coef_1 coef_2
coef_1 = k(i+1)/k(i)
coef_2 = k(i+2)/k(i)
syms func1
psi_t1 = coef_1*psi_t0;
func1 = exp(j*((psi_t1 - psi_t0) + (zeta_t1 - zeta_t0))) - radar_obv1;
syms func3
func3 = exp(j*4*(coef_1*psi_t0 + zeta_t1)) - exp(j*4*(psi_t0 + zeta_t0)) -sym(radar4_obv1);
syms func2
psi_t2 = coef_2*psi_t0;
func2 = exp(j*((psi_t2 - psi_t0) + (zeta_t2 - zeta_t0))) - radar_obv2;
syms func4
func4 = exp(j*4*(coef_2*psi_t0 + zeta_t2)) - exp(j*4*(psi_t0 + zeta_t0)) - sym(radar4_obv2);
end
s = solve([func1==0, func3==0, func2==0, func4==0], [psi_t0, zeta_t0, zeta_t1,zeta_t2])
s1 = vpasolve([func1==0, func3==0, func2==0, func4==0], [psi_t0, zeta_t0, zeta_t1,zeta_t2])
3 件のコメント
Walter Roberson
2016 年 1 月 5 日
When a 0x1 sym is returned it means there is no solution (or none that could be found.)
回答 (1 件)
Walter Roberson
2016 年 1 月 5 日
You used the wrong syntax for solve() at the MATLAB level. If you were operating at the MuPAD level, your syntax for the solve() call would be fine: at the MuPAD level, the first argument to solve is the list or set of equations and the second argument is the list or set of variables to solve over. But at the MATLAB level, each of them needs to become a distinct argument:
s = solve(func1==0, func3==0, func2==0, func4==0, psi_t0, zeta_t0, zeta_t1,zeta_t2)
No distinction is made syntactically between equations and variables to solve for.
The solution might take a fair bit of time and memory for solve(), so I would recommend you skip that and go directly to vpasolve() (which has the same syntax as solve)
If my calculations are correct then:
psi_t0 = 1020310/221001 - (10/11)*Pi - (10/11)*zeta_t2
zeta_t0 = -314164753/192418204 - (1/11)*Pi + (10/11)*zeta_t2
zeta_t1 = -11366221/13923063 - (1/22)*Pi + (21/22)*zeta_t2
and zeta_t2 is any value (probably has to be non-infinite and maybe non-zero). That is, my calculations appear to indicate that although there are 4 equations, the 4th one is dependent on the others.
2 件のコメント
Walter Roberson
2016 年 1 月 6 日
The equations are not independent. Solving for three variables and substituting that in leaves you with 0 for the fourth question. The value of the fourth variable cannot be determined uniquely. All you can do is avoid analytic problems like division by 0 or by infinity: any value of zeta_t2 that does not cause a division by 0 or infinity problems is a solution to the equations.
I did not use vpasolve(): I worked through the equations one step at a time, solving for one variable, substituting, solve for the next... The first two went easily. The third one caused problems that looked like I was going to run out of memory. To handle that, I substituted symbols for each of the constants (leaving the general form exactly the same) and took a symbolic solution, which generated an expression containing a RootOf(). The value of a RootOf() is all of the values that make the given expression 0 -- the roots of the given equation. I then substituted the constants into the symbolic solution, which canceled out portions of the expression in the RootOf(). Simplify the expression and it turned out to have a relatively simple real-valued solution (it was not immediately obvious that it would; it looked like it was going to be a complex solution but it turned out the imaginary part could be proven to be 0). With the three values psi_t0, zeta_t0, zeta_t1 now determined in terms of zeta_t2, substituting into the equations gave 0 for the 4th equation, indicating a dependency that cannot be narrowed to one particular zeta_t2.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!