当 MATLAB 无法找到明确的解决方案时,任何可能的步骤?
Any possible step when MATLAB is unable to find explicit solution?
我正在尝试使用 MATLAB 解决一个问题,其中我有 9 个未知数和 8 个方程,我的目标是将 F
的值写为 x2: F=f(x2)
的函数,所以然后我可以给 x2
不同的值并获得 F
。实现代码为:
%-------- Variables description -------
%3 constants: P, h and c
%9 unknowns: F, x1,...,x8
syms F P h c x1 x2 x3 x4 x5 x6 x7 x8
%--------System of 8 Equations---------
Eq1 = F == P/(x1*x2/x3);
Eq2 = x1 == x3 - h;
Eq3 = x4 == x2 - x1;
Eq4 = x5 == sqrt(x4^2+(h-c)^2);
Eq5 = x6 == sqrt(x3^2+(x1+x4)^2);
Eq6 = x6 == 3*x5;
Eq7 = x7 == atan((h-c)/x4);
Eq8 = x8 == atan(x3/(x1+x4));
%----------------Solver----------------
Solution = solve([Eq1, Eq2, Eq3, Eq4, Eq5, Eq6, Eq7, Eq8],...
[F P c h x1 x3 x4 x5 x6 x7 x8]);
%----- Solution desired: F=f(x2) ------
Solution.F
然而,这段代码的输出是:
"Unable to find an explicit solution.".
我不确定为什么会遇到这个问题。是否有可能得到解决方案?
下面的代码帮我解决了。然后,您可以在 Eq9 中生成不同的解决方案 x2
。您的问题是您将 P, c, h
交给求解器。因此它不会将它们视为给定常量。
syms F P h c x1 x2 x3 x4 x5 x6 x7 x8
%--------System of 8 Equations---------
Eq1 = F == P/(x1*x2/x3);
Eq2 = x1 == x3 - h;
Eq3 = x4 == x2 - x1;
Eq4 = x5 == sqrt(x4^2+(h-c)^2);
Eq5 = x6 == sqrt(x3^2+(x1+x4)^2);
Eq6 = x6 == 3*x5;
Eq7 = x7 == atan((h-c)/x4);
Eq8 = x8 == atan(x3/(x1+x4));
Eq9 = x2 == 5;
%----------------Solver----------------
Solution = solve([Eq1, Eq2, Eq3, Eq4, Eq5, Eq6, Eq7, Eq8, Eq9],...
[F x1 x2 x3 x4 x5 x6 x7 x8]);
%----- Solution desired: F=f(x2) ------
Solution.F
此外,您可以使用 fsolve
作为非线性方程的数值求解器
Link 到文档 Matlab Documentation for FSolve
我正在尝试使用 MATLAB 解决一个问题,其中我有 9 个未知数和 8 个方程,我的目标是将 F
的值写为 x2: F=f(x2)
的函数,所以然后我可以给 x2
不同的值并获得 F
。实现代码为:
%-------- Variables description -------
%3 constants: P, h and c
%9 unknowns: F, x1,...,x8
syms F P h c x1 x2 x3 x4 x5 x6 x7 x8
%--------System of 8 Equations---------
Eq1 = F == P/(x1*x2/x3);
Eq2 = x1 == x3 - h;
Eq3 = x4 == x2 - x1;
Eq4 = x5 == sqrt(x4^2+(h-c)^2);
Eq5 = x6 == sqrt(x3^2+(x1+x4)^2);
Eq6 = x6 == 3*x5;
Eq7 = x7 == atan((h-c)/x4);
Eq8 = x8 == atan(x3/(x1+x4));
%----------------Solver----------------
Solution = solve([Eq1, Eq2, Eq3, Eq4, Eq5, Eq6, Eq7, Eq8],...
[F P c h x1 x3 x4 x5 x6 x7 x8]);
%----- Solution desired: F=f(x2) ------
Solution.F
然而,这段代码的输出是:
"Unable to find an explicit solution.".
我不确定为什么会遇到这个问题。是否有可能得到解决方案?
下面的代码帮我解决了。然后,您可以在 Eq9 中生成不同的解决方案 x2
。您的问题是您将 P, c, h
交给求解器。因此它不会将它们视为给定常量。
syms F P h c x1 x2 x3 x4 x5 x6 x7 x8
%--------System of 8 Equations---------
Eq1 = F == P/(x1*x2/x3);
Eq2 = x1 == x3 - h;
Eq3 = x4 == x2 - x1;
Eq4 = x5 == sqrt(x4^2+(h-c)^2);
Eq5 = x6 == sqrt(x3^2+(x1+x4)^2);
Eq6 = x6 == 3*x5;
Eq7 = x7 == atan((h-c)/x4);
Eq8 = x8 == atan(x3/(x1+x4));
Eq9 = x2 == 5;
%----------------Solver----------------
Solution = solve([Eq1, Eq2, Eq3, Eq4, Eq5, Eq6, Eq7, Eq8, Eq9],...
[F x1 x2 x3 x4 x5 x6 x7 x8]);
%----- Solution desired: F=f(x2) ------
Solution.F
此外,您可以使用 fsolve
作为非线性方程的数值求解器
Link 到文档 Matlab Documentation for FSolve