在运行时,我有代码应该正确地使用拉格朗日乘数来找到函数的最大值/最小值:
clear all
syms x y L;
f = x^4+2*y^4;
g = x^2+5*y^2+2*y^2-10;
firstpart=jacobian(f,[x y])-L*jacobian(g,[x y]);
[Lsoln,xsoln,ysoln]=solve(firstpart,x^2+5*y^2+2*y^2-10);
subs(f,{x,y},{xsoln,ysoln})
% The coordinates that correspond with the greatest and smallest values
% above are the maximum and minimum, respectively. 然而,当我运行它时,我会得到四个错误:
使用sym.getEqnsVars>checkVariables错误(第92行)第二个参数必须是符号变量的向量。 sym.getEqnsVars (第62行)checkVariables(Vars)中的错误; solve>getEqns (第450行) eqns中的错误,vars = sym.getEqnsVars(argv{:}); 在solve (第225行) eqns,vars,options =getEqns(varargin{:})中出错;
有人能帮忙吗?
发布于 2015-10-28 06:32:16
你正在传递两个方程作为单个的参数求解,这是不可能的。你必须将两者都放入一个数组中
[Lsoln,xsoln,ysoln]=solve([firstpart,x^2+5*y^2+2*y^2-10] ); https://stackoverflow.com/questions/33384099
复制相似问题