[已解决] vpasolve解非线性报错

[复制链接]
Mr.yan123 发表于 2022-11-4 10:26:48
本帖最后由 Mr.yan123 于 2022-11-4 15:08 编辑

这是源代码
syms  x1 x2 x3 x4 x5 x6
X=74;
Y=-10;
Z=0;
M=180;
N=20;
eq1= N*cos(x1 - x3)*cos(x4 + x5) - x2*sin(x1) + M*cos(x1 - x3)*cos(x4)+X;
eq2= x2*cos(x1) + N*sin(x1 - x3)*cos(x4 + x5) + M*sin(x1 - x3)*cos(x4)-Z;
eq3= Y+N*sin(x4 + x5)+ M*sin(x4);
eq4= Z*sin(x1) - X*cos(x1)-(cos(x3)*(N*cos(x4 + x5) + M*cos(x4)));
eq5= Z*cos(x1) + X*sin(x1)-(x2 - M*cos(x4)*sin(x3) - N*cos(x4)*cos(x5)*sin(x3) + N*sin(x3)*sin(x4)*sin(x5));
eq6= x2*sin(x3) - X*cos(x1 - x3) + Z*sin(x1 - x3)-(N*cos(x4 + x5) + M*cos(x4));
eq7= Z*cos(x1 - x3) - x2*cos(x3) + X*sin(x1 - x3);
eq8= x2*cos(x4)*sin(x3) - Y*sin(x4) - M - X*cos(x1)*cos(x3)*cos(x4) - Z*cos(x1)*cos(x4)*sin(x3) + Z*cos(x3)*cos(x4)*sin(x1) - X*cos(x4)*sin(x1)*sin(x3)- N*cos(x5);
eq9= X*cos(x1)*cos(x3)*sin(x4) - x2*sin(x3)*sin(x4) - Y*cos(x4) + Z*cos(x1)*sin(x3)*sin(x4) - Z*cos(x3)*sin(x1)*sin(x4) + X*sin(x1)*sin(x3)*sin(x4)- N*sin(x5);
eq10= (x2*sin(x3 + x4 + x5))/2 - N - (x2*sin(x4 - x3 + x5))/2 - Y*sin(x4 + x5) - M*cos(x5) - (X*cos(x1 - x3 + x4 + x5))/2 - (X*cos(x3 - x1 + x4 + x5))/2 + (Z*sin(x1 - x3 + x4 + x5))/2 - (Z*sin(x3 - x1 + x4 + x5))/2;
eq11= (x2*cos(x4 - x3 + x5))/2 - (x2*cos(x3 + x4 + x5))/2 + Y*cos(x4 + x5) - M*sin(x5) - (Z*cos(x1 - x3 + x4 + x5))/2 + (Z*cos(x3 - x1 + x4 + x5))/2 - (X*sin(x1 - x3 + x4 + x5))/2 - (X*sin(x3 - x1 + x4 + x5))/2;
eq12= Z*cos(x1)*cos(x3)*sin(x6) - M*cos(x5)*cos(x6) - x2*cos(x3)*sin(x6) - Y*cos(x4)*cos(x6)*sin(x5) - Y*cos(x5)*cos(x6)*sin(x4) - N*cos(x6) - X*cos(x1)*sin(x3)*sin(x6) + X*cos(x3)*sin(x1)*sin(x6) + Z*sin(x1)*sin(x3)*sin(x6) + x2*cos(x4)*cos(x5)*cos(x6)*sin(x3) - x2*cos(x6)*sin(x3)*sin(x4)*sin(x5) - X*cos(x1)*cos(x3)*cos(x4)*cos(x5)*cos(x6) - Z*cos(x1)*cos(x4)*cos(x5)*cos(x6)*sin(x3) + Z*cos(x3)*cos(x4)*cos(x5)*cos(x6)*sin(x1) + X*cos(x1)*cos(x3)*cos(x6)*sin(x4)*sin(x5) - X*cos(x4)*cos(x5)*cos(x6)*sin(x1)*sin(x3) + Z*cos(x1)*cos(x6)*sin(x3)*sin(x4)*sin(x5) - Z*cos(x3)*cos(x6)*sin(x1)*sin(x4)*sin(x5) + X*cos(x6)*sin(x1)*sin(x3)*sin(x4)*sin(x5);
eq13= N*sin(x6) + M*cos(x5)*sin(x6) - x2*cos(x3)*cos(x6) + Z*cos(x1)*cos(x3)*cos(x6) - X*cos(x1)*cos(x6)*sin(x3) + X*cos(x3)*cos(x6)*sin(x1) + Y*cos(x4)*sin(x5)*sin(x6) + Y*cos(x5)*sin(x4)*sin(x6) + Z*cos(x6)*sin(x1)*sin(x3) - x2*cos(x4)*cos(x5)*sin(x3)*sin(x6) + x2*sin(x3)*sin(x4)*sin(x5)*sin(x6) + X*cos(x1)*cos(x3)*cos(x4)*cos(x5)*sin(x6) + Z*cos(x1)*cos(x4)*cos(x5)*sin(x3)*sin(x6) - Z*cos(x3)*cos(x4)*cos(x5)*sin(x1)*sin(x6) - X*cos(x1)*cos(x3)*sin(x4)*sin(x5)*sin(x6) + X*cos(x4)*cos(x5)*sin(x1)*sin(x3)*sin(x6) - Z*cos(x1)*sin(x3)*sin(x4)*sin(x5)*sin(x6) + Z*cos(x3)*sin(x1)*sin(x4)*sin(x5)*sin(x6) - X*sin(x1)*sin(x3)*sin(x4)*sin(x5)*sin(x6);
vpasolve ([eq1,eq2,eq3,eq4,eq5,eq6,eq7,eq8,eq9,eq10,eq11,eq12,eq13],[x1,x2,x3,x4,x5,x6],[-29*pi/60,31*pi/60;100,150;1.4242,1.5289;-pi/60,pi/60;-pi/60,pi/60;-pi/60,pi/60]);
这是错误

错误使用 mupadengine/feval_internal
More equations than variables is only supported for polynomial systems.

出错 sym/vpasolve (第 172 行)
    sol = eng.feval_internal('symobj::vpasolve',eqns,vars,X0);

出错 vpasolve (第 20 行)
vpasolve
([eq1,eq2,eq3,eq4,eq5,eq6,eq7,eq8,eq9,eq10,eq11,eq12,eq13],[x1,x2,x3,x4,x5,x6],[-29*pi/60,31*pi/60;100,150;1.4242,1.5289;-pi/60,pi/60;-pi/60,pi/60;-pi/60,pi/60]);

这是哪里有问题呢?
这个方程用fsolve可以求解,但是解不在范围内,或者大哥们有fsolve函数设置接的范围也可以。

最佳答案


shihe 发表于 2022-11-6 10:25:08
在楼主给定的范围内是无解的,把第三个参数设定的下限值稍微放宽点,比如由1.5289改成1.5902,就可以得到解了(还是多解):
1:
x1: -1.51840002203126
x2: 125.813224386832
x3: 1.59019963117893
x4: 0.0492227011003703
x5: 0.00798305380453663
x6: -0.0523586891546369

2:
x1: -1.51842969562572
x2: 125.812812499077
x3: 1.59018868413375
x4: 0.0510280142357323
x5: -0.0100694126184423
x6: -0.0521665084718667

3:
x1: -1.51840516402486
x2: 125.81003218717
x3: 1.59019803732974
x4: 0.0520625879372886
x5: -0.0204089479266
x6: -0.0502083928595633

5 条回复


TouAkira 发表于 2022-11-5 21:22:19
提示告诉你了,vpasolve只能解多项式构成的超定方程组,不适于超越方程组。改用
F = [eq1,eq2,eq3,eq4,eq5,eq6,eq7,eq8,eq9,eq10,eq11,eq12,eq13];
G = matlabFunction( F, 'vars', { [x1,x2,x3,x4,x5,x6] });
sol = fsolve( G, rand( 1, 6 ) )
G( sol )
可以求得一组解
sol = 3.33385988345779        157.281566834392        1.17000255204847        -0.0497362232495666        1.29487788795599        0.997239199723385
此时G的数值(即原方程组的绝对误差)都在 1e-9 这个量级上

shihe 发表于 2022-11-6 10:25:08
在楼主给定的范围内是无解的,把第三个参数设定的下限值稍微放宽点,比如由1.5289改成1.5902,就可以得到解了(还是多解):
1:
x1: -1.51840002203126
x2: 125.813224386832
x3: 1.59019963117893
x4: 0.0492227011003703
x5: 0.00798305380453663
x6: -0.0523586891546369

2:
x1: -1.51842969562572
x2: 125.812812499077
x3: 1.59018868413375
x4: 0.0510280142357323
x5: -0.0100694126184423
x6: -0.0521665084718667

3:
x1: -1.51840516402486
x2: 125.81003218717
x3: 1.59019803732974
x4: 0.0520625879372886
x5: -0.0204089479266
x6: -0.0502083928595633
回复此楼

Mr.yan123 发表于 2022-11-7 16:23:31
TouAkira 发表于 2022-11-5 21:22
提示告诉你了,vpasolve只能解多项式构成的超定方程组,不适于超越方程组。改用
F = [eq1,eq2,eq3,eq4,eq5, ...

我用fsolve函数求出的解不在范围内,老哥。

Mr.yan123 发表于 2022-11-7 16:24:29
shihe 发表于 2022-11-6 10:25
在楼主给定的范围内是无解的,把第三个参数设定的下限值稍微放宽点,比如由1.5289改成1.5902,就可以得到解 ...

您这个是如何实现的呢?我把约束去掉也是报错

TouAkira 发表于 2022-11-9 08:05:13
Mr.yan123 发表于 2022-11-7 04:23
我用fsolve函数求出的解不在范围内,老哥。

3楼 shihe 不是说了吗,你给的区间内本来就解不出来啊,你用不用fsolve,都改变不了方程组无解的事实啊。
非要加区间限制,就去换用 fmincon 对上述的G函数的模做优化,有解时,模值应非常接近零。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

相关帖子
相关文章
热门教程
站长推荐
快速回复 返回顶部 返回列表