How to improve accuracy in fsolve?
20 views (last 30 days)
Show older comments
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 Comment
Walter Roberson
on 4 Apr 2020
The equations in f cannot distinguish between a(1) and a(3), or between a(2) and a(4) .
Accepted Answer
Walter Roberson
on 3 Apr 2020
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
More Answers (1)
Alex Sha
on 4 Apr 2020
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
See Also
Categories
Find more on Systems of Nonlinear Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!