F solve error, how can I fix it?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Fares Sahli F2HYGC
am 27 Jun. 2020
Kommentiert: Fares Sahli F2HYGC
am 27 Jun. 2020
I receive the following error: fsolve stopped because the problem appears regular as measured by the gradient,
but the vector of function values is not near zero as measured by the
value of the function tolerance.
My code is as follows:
function F = root2d(x)
F(1) = -(118/121)*x(1)^2-(333/242)*x(2)^2-(196/121)*x(1)*x(2)+(63/121)*x(1)-(361/242)*x(2)-(724/121);
F(2) = (21/121)*x(1)^2+(299/484)*x(2)^2+(80/121)*x(1)*x(2)-(35/242)*x(1)+(391/484)*x(2)-256/121;
end
and the command I use is
fun = @root2d;
x0 = [1,1];
x = fsolve(fun,x0)
I've tried various combinations of x0 but had no effect, can someone please help?
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 27 Jun. 2020
The four roots are all complex values. You will not be able to find them using fsolve unless you split the x into two variables each, one for real part and one for imaginary part, OR you use a complex initial value.
5 Kommentare
Walter Roberson
am 27 Jun. 2020
syms x [1 2]
sol = solve(root2d(x))
vpa(sol.x1)
vpa(sol.x2)
Weitere Antworten (2)
John D'Errico
am 27 Jun. 2020
Bearbeitet: John D'Errico
am 27 Jun. 2020
There are no real solutions. First, I converted them to a problem that fimplicit can use.
F1 = @(x,y) -(118/121)*x.^2-(333/242)*y.^2-(196/121)*x.*y+(63/121)*x-(361/242)*y-(724/121);
F2 = @(x,y) (21/121)*x.^2+(299/484)*y.^2+(80/121)*x.*y-(35/242)*x+(391/484)*y-256/121;
So the same equations, changed using find and replace in the editor to insure no mistakes were made.
H2 = fimplicit(F2,[-500,500,-500,500]);
Your expression F(2) has a locus of solutions that form a hyperbola. Two hyperbolic arcs, extending to infinity in either direction.
The first however, has no real solutions at all. We can prove that using solve. For example, converting F1 to a symbolic form, if I use solve to find the two roots of the quadratic for X as a function of Y, we will find it involves a square root, of an expression that looks like this:
sqrt(-2.7438*Y^2 - 7.5058*Y - 23.069)
The sub-expression inside the sqrt is negative for ALL values of Y. Therefore all solutions for F1 are complex. It has no real solutions that will make it zero, for any inputs.
syms Y
fplot(-2.7438*Y^2 - 7.5058*Y - 23.069)
As I said, the solution involves the squre root of that value, which is always negative, as a parabolic arc.
As far as having received an error, the message was a correct assessment, although that was actually a warning message, not a true error. There simply are no real solutions to this set of equations.
0 Kommentare
RAVIKIRAN YALAMARTHI
am 27 Jun. 2020
Bearbeitet: RAVIKIRAN YALAMARTHI
am 27 Jun. 2020
g = @(x,y) -(118/121)*x.^2 -(333/242)*y.^2 -(196/121)*x.*y +(63/121)*x -(361/242)*y -(724/121);
h = @(x,y) (21/121)*x.^2 +(299/484)*y.^2 +(80/121)*x.*y -(35/242)*x +(391/484)*y -(256/121);
f = @(w) [g(w(1),w(2));h(w(1),w(2))];
w0 = [.1+.1*1i, .1 +.1*1i];
wRoot = fsolve(f,w0)
0 Kommentare
Siehe auch
Kategorien
Mehr zu Calculus finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!