Matlab V解决的未知数比方程多=>;没有解决方案

Matlab V解决的未知数比方程多=>;没有解决方案,matlab,solver,Matlab,Solver,我有3个方程和4个未知数要解。当然有解决方案,但vpasolve不会返回任何结果,如果我降到3个等式和3个未知数,效果会很好。我知道,有了更多的未知数,我就有了几乎无限多的解,那么在这种情况下,我该如何使它工作呢 这是我的密码: syms x y z theta1 theta2 theta3 phi1 xEquation = x == cos(theta1)*cos(phi1) + cos(theta1 + theta2)*cos(phi1) + cos(theta1 + theta2 + t

我有3个方程和4个未知数要解。当然有解决方案,但vpasolve不会返回任何结果,如果我降到3个等式和3个未知数,效果会很好。我知道,有了更多的未知数,我就有了几乎无限多的解,那么在这种情况下,我该如何使它工作呢

这是我的密码:

syms x y z theta1 theta2 theta3 phi1

xEquation = x == cos(theta1)*cos(phi1) + cos(theta1 + theta2)*cos(phi1) + cos(theta1 + theta2 + theta3)*cos(phi1)
yEquation = y == cos(theta1)*sin(phi1) + cos(theta1 + theta2)*sin(phi1) + cos(theta1 + theta2 + theta3)*sin(phi1)
zEquation = z == sin(theta1) + sin(theta1 + theta2) + sin(theta1 + theta2 + theta3)

x = 2;
y = 1.5;
z = 0;
sol = vpasolve([eval(xEquation), eval(yEquation), eval(zEquation)], [theta1, theta2, theta3, phi1], [-pi pi; -pi pi; -pi pi; -pi pi;]);

这将生成具有4个字段的sol struct,但它们是空的,没有解。

求解具有n个未知量的m方程,例如
m解是什么?感谢您的详细解释,我不太理解fmincon是如何工作的,但显然它是工作的。然而,我有一个问题,我必须为x,y和z的多个值解这些方程,并且每个连续解应该尽可能接近前一个解。t=0:0.1:1;x=1.5+0.5.*cos(8.*pi.*t);y=1.5+0.5.*sin(8.*pi.*t);z=1.*t.*one(尺寸(x));如果我对x,y,z使用这些值,我仍然可以得到解,但它们相差很远。我设法用vpasolve解决了这个问题,当eqns=未知时,它可以很好地工作,但是…好吧,根据您所说的,vpasolve将给您带来困难,这就是我试图在上面向您展示的,正确的工具是
fmincon
。我根据时间的变化更新答案
x,y,z
。我的答案很长,你可以先阅读
fmincon
,然后如果你有问题,可以打开聊天讨论谢谢Adam,我设法自己做了循环,但正如我所说的问题是,我这样做时得到的解决方案是这样的,每个连续的解决方案必须尽可能接近前一个解决方案,例如,如果θ1(1)为0.5,则θ1(2)必须尽可能接近0.5。不管怎样,我找到了答案,我用与vpasolve相同的方法,在每个解之后,我重新计算lb和ub,所以我有这个lb=sol(n,:)-步骤;ub=sol(n,:)+阶跃;在回路内部,步长是允许的偏差。我真的很想和你们谈谈fmincon:)所以在我实现了这个更改之后,我现在得到了更接近的解决方案,我还没有在我的主代码中实现它,看看它是如何实际工作的,但到目前为止还不错。我如何打开与您的聊天窗口?
x-3y+z = 2
x-y+5z = 5
syms x y z

eq1 = x-3*y+z ==2;
eq2 = x-y+5*z ==5;
sol = solve(eq1, eq2, x, y);
sol.x
sol.y
sol.x = 13/2 - 7*z
sol.y = 3/2 - 2*z
syms x y z theta1 theta2 theta3 phi1
    
xEquation = 2 == cos(theta1)*cos(phi1) + cos(theta1 + theta2)*cos(phi1) + cos(theta1 + theta2 + theta3)*cos(phi1);
yEquation = 1.5 == cos(theta1)*sin(phi1) + cos(theta1 + theta2)*sin(phi1) + cos(theta1 + theta2 + theta3)*sin(phi1);
zEquation = 0 == sin(theta1) + sin(theta1 + theta2) + sin(theta1 + theta2 + theta3);
  
    
sol = solve(xEquation, yEquation, zEquation, theta1, theta2, theta3);
sol.theta1 = [-pi*(2*n - 1); pi*(2*m + 1); pi*k; pi*k]
sol.theta2 = [pi*(2*m + 1);  -pi*(2*n - 1);  -pi*(2*n - 1); z]
sol.theta3 = [pi*k; pi*k; pi*(2*m + 1); pi*(2*m + 1)] 
phi1 is the parameter 
X = [sol.theta1(1); sol.theta2(1); sol.theta3(1); phi1]
X = [-pi*(2*n - 1); pi*(2*m + 1); pi*k; phi1]
t = 0:0.1:1;
x = 1.5 + 0.5 .* cos(8 .* pi .* t);
y = 1.5 + 0.5 .* sin(8 .* pi .* t); 
z = 1 .* t .* ones(size(x));

lb = -pi*ones(1, 4);
ub = -lb;

p0 = zeros(1,4);
sol = cell(1,length(t));

for i = 1:length(t)
    sol{i} = fmincon(@(p)0,p0,[],[],[],[],lb,ub,@(p)nonlincon(x(i),y(i), z(i), p(1), p(2), p(3), p(4)));


end


function [c, ceq] = nonlincon(x,y, z, theta1, theta2, theta3, phi1)

    c = [];
    ceq(1) = cos(theta1)*cos(phi1) + cos(theta1 + theta2)*cos(phi1) + cos(theta1 + theta2 + theta3)*cos(phi1)-x;
    ceq(2) = cos(theta1)*sin(phi1) + cos(theta1 + theta2)*sin(phi1) + cos(theta1 + theta2 + theta3)*sin(phi1)-y;
    ceq(3) = sin(theta1) + sin(theta1 + theta2) + sin(theta1 + theta2 + theta3)-z;
end
sol{2}.(1) = pheta1
sol{2}.(2) = pheta2
sol{2}.(3) = pheta3
sol{2}.(4) = phi1