MATLAB: ” fsolve” to solve a nonlinear system with two unknowns – wrong results!

fsolve

Hello,
I am trying to solve a system of nonlinear equations with two unknowns. I am using "fsolve" to do so (and I know what results/answers I should get). However, the values I get are wrong! The code containing the function of nonlinear equations is added below(pfun). Am I doing something wrong in passing parameters, etc? In the command line I first give an initial guess by entering: x0 = [0,0] and then I enter: S = fsolve(@pfun, x0) then I get wrong values in S. Why is that so?
Here is the code in the function:
function F = pfun(x)
w = 31;
n = 10;
m = 6;
F = [2.*(1-2.*x(1)).*(1-x(1).^(m+1))./ (1-2.*x(1)).* (1-x(1).^(m+1)) + w.*(1-x(1)).*(1-(2.*x(1)).^ (m+1)) - x(2); 1-(1-x(2).^(n-1))-x(1)];
I highly appreciate your help. Thank you.

Best Answer

When I tried I get the following:
Equation solved.
fsolve completed because the vector of function values is near zero
as measured by the default value of the function tolerance, and
the problem appears regular as measured by the gradient.
<stopping criteria details>
S =
1.0003 1.0000
Then I tried checking the answer:
pfun(S)
ans =
1.0e-12 *
-0.3917
0.0209
This looks correct to me. If you want a different answer, try a different starting point, or double-check your equations to ensure that they are doing what you think.
One more thing: it would help if you would format your code using the {} Code button. But your code was short enough that I was able to format it for myself.
Alan Weiss
MATLAB mathematical toolbox documentation