Failure in initial objective function evaluation. FSOLVE cannot continue. Please help:(
18 ビュー (過去 30 日間)
古いコメントを表示
I have a system of 5 equations to solve which are originally in symbolic form
eqnA = m_s - ((A_sy*P_e)/sqrt(T_e))*sqrt(gamma/R)*M_sy*((1 + ((gamma-1)/2)*M_sy^2)^(-(gamma+1)/(2*(gamma-1))))*eta_s == 0;
eqnB = m_p - ((A_py*P_g)/sqrt(T_g))*sqrt(gamma/R)*M_py*((1 + ((gamma-1)/2)*M_py^2)^(-(gamma+1)/(2*(gamma-1))))*eta_s - m_p == 0;
eqnC = A_py + A_sy - A_3 == 0;
eqnD = P_g/P_c - (1 + (gamma-1)/2*M_py^2)^(gamma/(gamma-1)) == 0;
eqnE = P_e/P_c - (1 + (gamma-1)/2*M_sy^2)^(gamma/(gamma-1))== 0;
I also have known values
val_m_p = 0.3745, val_m_s = 0.1175, val_T_g = 298.0124, val_T_e = 298.0001, val_A_3 = 1.767*10^-4, val_P_e = 4.0000e+06, val_P_g = 5.1e+06
I substituted these values into the equations above, converted the equations into a function handle and proceeded to solve for the remaining 5 unknown variables
%flow expansion
eqnAx = subs(eqnA, {P_e, T_e, m_s}, {val_P_e, val_T_e, val_m_s})
eqnBx = subs(eqnB, {P_g, T_g, m_p}, {val_P_g, val_T_g, val_m_p})
eqnCx = subs(eqnC, A_3, val_A_3)
eqnDx = subs(eqnD, P_g, val_P_g)
eqnEx = subs(eqnE, P_e, val_P_e)
g = matlabFunction([eqnAx; eqnBx; eqnCx; eqnDx; eqnEx])
options = optimset('Display','off');
x = fsolve(g, [0 0 0 0 0], options)
With g being
g =
function_handle with value:
@(A_py,A_sy,M_py,M_sy,P_c)[sqrt(7.0).*7.576938695805846e+1.*2.965820800757861e+6.*5.119801572077356e+7.*A_sy.*M_sy.*1.0./(M_sy.^2./5.0+1.0).^3.*(-4.518723221790994e-13)+1.174896374819055e-1==0.0;sqrt(7.0).*7.576938695805846e+1.*2.965820800757861e+6.*5.119907258219913e+7.*A_py.*M_py.*1.0./(M_py.^2./5.0+1.0).^3.*(-5.761966781546089e-13)==0.0;A_py+A_sy-1.767e-4==0.0;5.100744432356854e+6./P_c-(M_py.^2./5.0+1.0).^(7.0./2.0)==0.0;4.000005838383844e+6./P_c-(M_sy.^2./5.0+1.0).^(7.0./2.0)==0.0]
However, I had error message
Not enough input arguments.
Error in
symengine>@(A_py,A_sy,M_py,M_sy,P_c)[sqrt(7.0).*7.576938695805846e+1.*2.965820800757861e+6.*5.119801572077356e+7.*A_sy.*M_sy.*1.0./(M_sy.^2./5.0+1.0).^3.*(-4.518723221790994e-13)+1.174896374819055e-1==0.0;sqrt(7.0).*7.576938695805846e+1.*2.965820800757861e+6.*5.119907258219913e+7.*A_py.*M_py.*1.0./(M_py.^2./5.0+1.0).^3.*(-5.761966781546089e-13)==0.0;A_py+A_sy-1.767e-4==0.0;5.100744432356854e+6./P_c-(M_py.^2./5.0+1.0).^(7.0./2.0)==0.0;4.000005838383844e+6./P_c-(M_sy.^2./5.0+1.0).^(7.0./2.0)==0.0]
Error in fsolve (line 248)
fuser = feval(funfcn{3},x,varargin{:});
Error in Untitled10 (line 158)
x = fsolve(g, [0 0 0 0 0], options)
Caused by:
Failure in initial objective function evaluation. FSOLVE cannot continue.
I'm not too sure where it went wrong since the number of initialization parameters is the same as the number of unknowns. Please help:(
0 件のコメント
回答 (1 件)
Alan Weiss
2020 年 12 月 15 日
The error is that fsolve expects just one input argument, and you have many (I count 5 arguments, A_py,A_sy,M_py,M_sy,P_c) :
g =
function_handle with value:
@(A_py,A_sy,M_py,M_sy,P_c)[sqrt(7.0).*7.576938695805846e+1.*2.965820800757861e+6.*5.119801572077356e+7.*A_sy.*M_sy.*1.0./(M_sy.^2./5.0+1.0).^3.*(-4.518723221790994e-13)+1.174896374819055e-1==0.0;sqrt(7.0).*7.576938695805846e+1.*2.965820800757861e+6.*5.119907258219913e+7.*A_py.*M_py.*1.0./(M_py.^2./5.0+1.0).^3.*(-5.761966781546089e-13)==0.0;A_py+A_sy-1.767e-4==0.0;5.100744432356854e+6./P_c-(M_py.^2./5.0+1.0).^(7.0./2.0)==0.0;4.000005838383844e+6./P_c-(M_sy.^2./5.0+1.0).^(7.0./2.0)==0.0]
To fix this issue, use the vars argument in matlabFunction:
g = matlabFunction([eqnAx; eqnBx; eqnCx; eqnDx; eqnEx],'vars',{A_py,A_sy,M_py,M_sy,P_c})
For another example using matlabFunction for optimization, see Calculate Gradients and Hessians Using Symbolic Math Toolbox™.
Alan Weiss
MATLAB mathematical toolbox documentation
4 件のコメント
Walter Roberson
2020 年 12 月 21 日
remove the == 0 in defining eqn variables. If they must be expressed as equations then take lhs(X)-rhs(X) where X is your vector of equations.
参考
カテゴリ
Help Center および File Exchange で Calculus についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!