help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: fsolve not finding correct answer


From: address@hidden
Subject: Re: fsolve not finding correct answer
Date: Sun, 11 Feb 2007 13:26:53 -0800 (PST)

I can't understand your formulas like 
$ p = \int_{-k}^{k} f_B(y,\sigma) dy $ 
-they come to me as char symbols.
If you have integrals, your funcs are non-smooth & noisy, so of course
fsolve will fail - I can give you even example with linear system & nVars=2.
You should try using other funcs, like nonSmoothSolve from OpenOpt 0.35
beta.
WBR, Dmitrey.


Aivo Jürgenson-2 wrote:
> 
> Hello,
> 
> I'm trying to use fsolve for finding unknown $k$ in a somewhat complex 
> equation
> 
>       $ p = \int_{-k}^{k} f_B(y,\sigma) dy $
> 
> where f_B is the probability density function of "Bessel's" 
> distribution and equals to
> 
>       p=(1/(pi.*sigma)).*besselk(0,(abs(y)./sigma));
> 
> where besselk is the standard Octave function.
> 
> The problem is that the fsolve function doesn't do a very good job and 
> sometimes gives "iteration is not making good progress" and 
> therefore completely wrong answer as well.
> 
> The appropriate code is given in the atree_bessel_find_range.m file in the 
> attachment. I'm using the 2.1.73-13 Debian package of Octave.
> 
> Anybody has some hints about how to persuade fsolve giving the correct 
> answer or perhaps somebody could suggest a different function for solving 
> the equation in the first place?
> 
> Aivo Jürgenson
> 
> function k=atree_bessel_find_range(sigma,p)
> 
> # We define temporary function
> str = sprintf('function p=atree_bessel_find_range_temp(x)
> p=atree_bessel_in_range(%g, min(-x, x), max(-x,x)) - %g; endfunction',
> sigma, p);
>  eval(str);
> 
> # and then solve it for atree_bessel_find_range_temp(x)=0
> 
> k0 = [1,0.1,0.01,0.001,sigma];
> 
> for i = 1:size(k0)(2)
>   [k, info, msg] = fsolve('atree_bessel_find_range_temp',0.1);
>   if (info == 1)
>     break;
>   endif
> endfor
> 
> k = abs(k);
> 
> if (info == 1)
>   solution = atree_bessel_in_range(sigma, -k, k);
>   if (!atree_compare_round(p, solution))
>     fprintf(stderr, "Pr[%g<X<%g]=%g, but Pr[%g<Bessel(%g)<%g]=%g\n", -k,
> k, p, -k, sigma, k, solution);
>     fprintf(stderr, "atree_bessel_find_range didn't get the correct range.
> fsolve:%s\n",msg);
>     perror("fsolve", info);
>   endif
> else
>   fprintf(stderr, "Pr[%g<X<%g]=%g, but Pr[%g<Bessel(%g)<%g]=%g\n", -k, k,
> p, -k, sigma, k, 
> atree_bessel_in_range(sigma, -k,$  fprintf(stderr,
> "atree_bessel_find_range didn't find the correct range: fsolve 
> %s\n",msg);
>   perror("fsolve", info);
> endif
> 
> endfunction
> 
> 
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://www.cae.wisc.edu/mailman/listinfo/help-octave
> 
> 

-- 
View this message in context: 
http://www.nabble.com/fsolve-not-finding-correct-answer-tf3210103.html#a8915158
Sent from the Octave - General mailing list archive at Nabble.com.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]