Hello Chris,
Thanks a lot for your answer! It's very interesting. By now I just need the 
bisection method: nsolve(eq,c2,(1,1000),solver='bisect'). But I will keep 
in mind the continuation method for the future.
Cheers,
Camille

Le jeudi 26 juin 2014 18:36:58 UTC+2, Chris Smith a écrit :
>
> Above 0, the function is monotonic but is ill-behaved in that it is very 
> flat; this can cause troubles for different solver routines. A slow but 
> robust method is bisection
>
> >>> nsolve(eq,c2,(1,1000),solver='bisect')
> mpf('22.964256014441664')
>
> Using that, you don't need a very precise range for the root.
>
> Also, once you have the root, continuation to a new root at a new set of 
> parameters can be attempted by slowly varying the old parameters until they 
> become the new parameters. This is called "the continuation method" and 
> should be able to easily find information on that. Here is an example.
>
>
> Your equation now is 3/10 - 1/log(c2 + 1) + 17/(50*c2). Let's say you want 
> to vary the 3/10 to 5/10, the numerator of 1 on the log term to 2 and the 
> 17/50 to 2, too. Let's make a function to give a linear variation from a to 
> b in n steps:
>
> >>> def vary(a,b,n=10):
> ...  return a + i*(b-a)/S(n)
> ...
>
>
> >>> n = 10
> >>> ceq=vary(S(3)/10, s(5)/10, n)-vary(1, 2, n)/log(c2+1)+vary(S(17)/50, 
> 2, n)/c2
> >>> ceq
> i/50 - (i/10 + 1)/log(c2 + 1) + 3/10 + (83*i/500 + 17/50)/c2
>
> We already know that a solution for the original equation is about 22 so 
> make that your initial guess
>
> >>> g=22
>
> Then increment the i value to move you toward your desired equation, 
> keeping the new solution as your new guess.
>
> >>> for iv in range(n+1):
> ...  g=nsolve(ceq.subs(i,iv),c2,g)
> ...
>
> So what is the final solution? The guess that we got when using i=n
> >>> g
> mpf('35.36155261017116')
>
> And this is the desired equation that we got to by slowly varying the 
> coefficients:
>
> >>> ceq.subs(i, iv)
> 1/2 - 2/log(c2 + 1) + 2/c2
>
> You can't use continuation blindly; graphing is your friend. Don't forget 
> about plot in SymPy, too: e.g. plot(x+1,(x,-1,1)).
> /c
>

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sympy+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/f7d4e4de-fc76-4bb5-99e6-ef0727f006fe%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to