【发布时间】:2023-03-10 02:59:02
【问题描述】:
我必须求解以下函数的非线性方程组:
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('调用者', [脚本';']);
我不知道如何解决它。我也尝试用vpasolve 和solve 解决同样的问题。对于solve,它需要的时间太长,对于vpasolve,我得到一个错误,即非多边形方程中不允许使用符号参数。
有没有办法将字符串转换为函数(不是 matlabFunction 在这段代码中所做的句柄函数)?
我越来越绝望,因为我不想手动重写所有内容。
更新:我尝试求解二维系统,例如来自http://nl.mathworks.com/help/optim/ug/fsolve.html。我得到同样的错误,这是截图。
【问题讨论】:
标签: matlab optimization nonlinear-functions nonlinear-optimization