我必须解决以下函数的非线性方程组:
function eq = ts_7(A,B,C,D,E)
syms x
% dbstop if error
g = D * sin(C * atan( B*x - E * (B*x - atan(B*x)))) + A; % magic formula
eq5 = taylor(g, x, 'Order',1, 'ExpansionPoint',7) + 4296; % x^0
eq1 = taylor(g, x, 'Order',2, 'ExpansionPoint',7) - eq5 + 296.3; % x^1
eq2 = taylor(g, x, 'Order',3, 'ExpansionPoint',7) - eq1 - 79.77; % x^2
eq3 = taylor(g, x, 'Order',4, 'ExpansionPoint',7) - eq2 - 4.541; % x^3
eq4 = taylor(g, x, 'Order',5, 'ExpansionPoint',7) - eq3 - 0.03358; % x^4
eq{1} = matlabFunction(eq1) % syms to numeric function
eq{2} = matlabFunction(eq2)
eq{3} = matlabFunction(eq3)
eq{4} = matlabFunction(eq4)
eq{5} = matlabFunction(eq5)
end
我的主要是以下
opts = optimoptions('fsolve','InitDamping',0.005,'Algorithm','levenberg-marquardt');
init = [-1.3, 1.4, 4000, 0.12, 9]; % starting points
tic
coeff = fsolve(@(x)ts_7(x(1), x(2), x(3), x(4), x(5)), init,opts);
toc
和我一直得到的错误是
未定义的功能或变量“fuser”。
fsolve错误(第257行)
if~isempty(isoptimargdbl('FSOLVE',{'F','J'},fuser,JAC))
script_7中的错误(第11行)
coeff = fsolve(@(x)ts_7(x(1),x(2),x(3),x(4),x(5)),init,opts);
跑步时出错(第96行)
evalin('caller',[script';']);
我不知道如何修复它。我还尝试使用vpasolve和solve解决同样的问题。对于solve,它花费的时间太长,对于vpasolve,我得到的错误是非多边形方程中不允许使用符号参数。
有没有办法将字符串转换为函数(不是matlabFunction在此代码中正在执行的句柄函数)?
我变得绝望,因为我不想手工重写所有东西。