24小时热门版块排行榜    

查看: 1034  |  回复: 4
当前只显示满足指定条件的回帖,点击这里查看本话题的所有回帖

XiaoGuads

新虫 (初入文坛)

[求助] 数值解非线性方程组时找不到解,希望各位能帮帮我已有2人参与

function y=fun(x)
alpha=0.125*pi/180;x1=0;z1=5;x2=0;z2=25;L1=5;L2=5;f=30;h0=20;n2=1.49386;
y(1) = tan(alpha) - x(1)/x(2);
y(2) = n2*sin(atan((x1 - x(1))/(z1 - x(2))) - atan((x(2) - x(4))/(x(1) - x(3)))) - sin(pi/2 - alpha + atan((x1 - x(1))/(z1 - x(2)))) ;
y(3) = n2*sin(atan((x2 - x(3))/(z2 - x(4))) - atan((x(2) - x(4))/(x(1) - x(3)))) - sin(pi/2 + atan((x2 - x(3))/(z2 - x(4))));
y(4) = L1 + L2 - f + h0 - h0*n2 + n2*((x(1) - x(3))^2 + (x(2) - x(4))^2)^(1/2);
end
----------------------------------------------------------------------
命令行输入
>> fsolve('fun',[0.1 5.1 0.1 25.1])
----------------------------------------------------------------------
No solution found.

fsolve stopped because the relative size of the current step is less than the
default value of the step size tolerance squared, but the vector of function values
is not near zero as measured by the default value of the function tolerance.

合理的解应该是在初值附近的,可为什么解不出来呢
回复此楼
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

dingd

铁杆木虫 (职业作家)

【答案】应助回帖

1stOpt试试,不需初值,精度更高:
CODE:
Parameter x(4);
Constant alpha=0.125*pi/180,xx1=0,z1=5,xx2=0,z2=25,L1=5,L2=5,f=30,h0=20,n2=1.49386;
Function
tan(alpha) - x(1)/x(2);
n2*sin(atan((xx1 - x(1))/(z1 - x(2))) - atan((x(2) - x(4))/(x(1) - x(3)))) - sin(pi/2 - alpha + atan((xx1 - x(1))/(z1 - x(2)))) ;
n2*sin(atan((xx2 - x(3))/(z2 - x(4))) - atan((x(2) - x(4))/(x(1) - x(3)))) - sin(pi/2 + atan((xx2 - x(3))/(z2 - x(4))));
L1 + L2 - f + h0 - h0*n2 + n2*((x(1) - x(3))^2 + (x(2) - x(4))^2)^(1/2);

有周期性三角函数,多解:
1:
x1: 0.0108298192893512
x2: 4.96401563027804
x3: 11.024819043045
x4: -11.7300564127835

2:
x1: 0.0109088181961899
x2: 5.0000209101071
x3: -0.00562667845017508
x4: 25.00001407242
5楼2019-02-28 18:14:16
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
查看全部 5 个回答

竹一拿下

铜虫 (正式写手)


jjdg: 金币+1, 感谢参与 2019-01-31 00:28:29
2楼2019-01-30 17:49:49
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

hzlhm

至尊木虫 (著名写手)

【答案】应助回帖

★ ★ ★ ★ ★ ★ ★ ★ ★ ★
感谢参与,应助指数 +1
月只蓝: 金币+10, 感谢帮助! 2019-01-31 18:04:04
利用最小二乘法(lsqnonlin),可以求得
x1=0.0109083348225495 ;x2=4.99999947195261;x3=0.0384214997768871;4=25.0000321470904
验证:
y1 = tan(alpha) - x(1)/x(2)=-2.16860202711944e-09
y2 = n2*sin(atan((x1 - x(1))/(z1 - x(2))) - atan((x(2) - x(4))/(x(1) - x(3)))) - sin(pi/2 - alpha + atan((x1 - x(1))/(z1 - x(2)))) =5.90246506399546e-06
y3 = n2*sin(atan((x2 - x(3))/(z2 - x(4))) - atan((x(2) - x(4))/(x(1) - x(3)))) - sin(pi/2 + atan((x2 - x(3))/(z2 - x(4))))=-3.15643589759254e-05

» 本帖已获得的红花(最新10朵)

QQ:2120156492
3楼2019-01-31 14:39:33
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

XiaoGuads

新虫 (初入文坛)

送红花一朵
引用回帖:
3楼: Originally posted by hzlhm at 2019-01-31 14:39:33
利用最小二乘法(lsqnonlin),可以求得
x1=0.0109083348225495 ;x2=4.99999947195261;x3=0.0384214997768871;4=25.0000321470904
验证:
y1 = tan(alpha) - x(1)/x(2)=-2.16860202711944e-09
y2 = n2*sin(atan ...

我在这方面是小白,请问大神能否贴出代码呢,谢谢!
4楼2019-02-04 16:56:15
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
信息提示
请填处理意见