On 31 Jul., 09:01, Bilal <
bilalci...@googlemail.com> wrote:
> Thanks Bruno for your reply.
> I did some search on internet to find if there is anyway to avoid fzero returning complex outputs. I found an article that says "To avoid these problems, you need to bound your solution so that complex numbers are not generated, or you may need to adjust the output of your function to insure that it doesn't produce any complex outputs". However, it doesn't give any practical example that can help me solve my problem.
> Does anyone know how to bound the solution or adjust the output of the function.
>
>
>
> On Tuesday, July 31, 2012 3:17:07 PM UTC+9, Bruno Luong wrote:
> > Bilal <
bilalci...@googlemail.com> wrote in message <
9c4c2724-4fb2-4b8b...@googlegroups.com>...
>
> > > Does anyone know what is the reason behind this error.
>
> > The error message tells exactly what the problem is: your function returns complex output or infinity in some cases.
>
> > Bruno- Zitierten Text ausblenden -
>
> - Zitierten Text anzeigen -
You must have gamma in [0;1].
So try the following:
function result = FUNCgamma(gamma_strich, n)
gamma = (sin(gamma_strich))^2;
m=5;
W=31;
p = 1-(1-gamma)^(n-1);
term0 = 2 * (1 - (2 * p)); % * (1 - p));
term1 = W * (1 - (2 * p)^(m + 1)) * (1 - p);
term2 = (1 - 2 * p);
term3 = ((1 - p)^(m+1));
result = gamma - (term0 / (term1 + term2 * term3)) * ((1-p^(m
+1)));
The zero you search for will then be (sin(gamma_strich))^2 where
gamma_strich is the solution fzero returns to the calling program.
Best wishes
Torsten.