[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
## RE: help fsolve not getting correct answers

**From**: |
Windhorn, Allen E [ACIM/LSA/MKT] |

**Subject**: |
RE: help fsolve not getting correct answers |

**Date**: |
Tue, 2 Apr 2019 21:26:32 +0000 |

From: Help-octave [mailto:address@hidden On Behalf Of Imane E
>* I wrote this code:*
>* function y = f(x)*
>* ...*
>* And then used:*
>* [x, fval, info] = fsolve (@f, [1;2])*
>* to solve for x(1) and x(2) when a = b and c = d (where c and d are respective*
>* derivatives of a and b).*
>* I know that the x values are supposed to be x(1)=1000 and x(2)=0.5, as I*
>* previously solved this system by hand. However, fsolve gives me:*
>* x =*
>* -73.3172*
>* 9.6259*
If you make x = [1000;0.5] and put it into your function, the result is not
zero:
>*> x = [1000; 0.5];*
>*> f(x)*
ans =
-10.150
39.951
So the function you have defined is not the same function you solved by
hand. A solution to the Octave function is x = [-73.3172; 9.6259].
Probably the function you solved by hand is the correct one, since it comes
out to be round numbers, so you have to find out what is the difference
between that one and the one you wrote in Octave. There are an infinite
number of functions that have the solution you are looking for, and we don't
have any way to guess which one you need, so you will have to troubleshoot
your code yourself. This will be good practice. Good luck to you.
P.S. The function may have more than one solution.
Regards,
Allen