# How to improve accuracy in fsolve?

34 ビュー (過去 30 日間)
dimocritos 2020 年 4 月 3 日
コメント済み: dimocritos 2020 年 4 月 5 日
Hello to everyone,
I am unfamiliar with MATLAB software and I am trying to solve some nonlinear equations. The problem that I have is that the results are not accurate enough. I don't have any initial guess, but I know that the results must be between 0 and pi/2 rads. Any idees?
f=@(a) [(4/pi)*(1-2*cos(a(1))+2*cos(a(2))-2*cos(a(3))+2*cos(a(4)))-0.5;
(4/(5*pi))*(1-2*cos(5*a(1))+2*cos(5*a(2))-2*cos(5*a(3))+2*cos(5*a(4)));
(4/(7*pi))*(1-2*cos(7*a(1))+2*cos(7*a(2))-2*cos(7*a(3))+2*cos(7*a(4)));
(4/(17*pi))*(1-2*cos(17*a(1))+2*cos(17*a(2))-2*cos(17*a(3))+2*cos(17*a(4)))];
[r]=fsolve(f,[1 1 1 1])
(4/pi)*(1-2*cos(r(1))+2*cos(r(2))-2*cos(r(3))+2*cos(r(4)))-0.5
(4/(5*pi))*(1-2*cos(5*r(1))+2*cos(5*r(2))-2*cos(5*r(3))+2*cos(5*r(4)))
(4/(7*pi))*(1-2*cos(7*r(1))+2*cos(7*r(2))-2*cos(7*r(3))+2*cos(7*r(4)))
(4/(17*pi))*(1-2*cos(17*r(1))+2*cos(17*r(2))-2*cos(17*r(3))+2*cos(17*r(4)))
##### 1 件のコメント表示非表示 なし
Walter Roberson 2020 年 4 月 4 日
The equations in f cannot distinguish between a(1) and a(3), or between a(2) and a(4) .

サインインしてコメントする。

### 採用された回答

Walter Roberson 2020 年 4 月 3 日
fsolve cannot limit the range of values.
fzero can limit the range of variables but only for a single function in one variable.
vpasolve can limit the range of values.
You can often get useful results by minimizing sum of f squared over a range as fmincon can handle range constraints
##### 5 件のコメント表示非表示 4 件の古いコメント
dimocritos 2020 年 4 月 5 日
Thank you for your help and time. I managed to find a method.

サインインしてコメントする。

### その他の回答 (1 件)

Alex Sha 2020 年 4 月 4 日
There are multi-solutions with high enough accurancy, even given the range limition in [0, pi/2]:
1:
a1: 0.996298496311242
a2: 0.956610794085768
a3: 1.12078428609661
a4: 1.47219048531321
feval:
-1.58206781009085E-14
1.27222187258541E-15
-4.64461953483561E-15
-1.99564215307515E-16
2:
a1: 0.423201820072776
a2: 1.45258039750964
a3: 1.15702893242895
a4: 0.468494500989183
feval:
2.22044604925031E-15
-4.63654193564459E-15
7.59294323955735E-15
7.45663375320891E-15
3:
a1: 1.15702893242895
a2: 0.468494500989183
a3: 0.423201820072776
a4: 1.45258039750964
feval:
2.22044604925031E-15
-4.69308512998172E-15
7.59294323955735E-15
7.46702772275618E-15
##### 4 件のコメント表示非表示 3 件の古いコメント
dimocritos 2020 年 4 月 5 日
Thank you both for your help and time. I managed to find a method.

サインインしてコメントする。

R2019b

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!