I tried using nsolve like you mentioned and got it to work. I then tried 
again, except adding a bound, and it produced the following error:

from sympy import *

M_3a = symbols('M_3a')
eqn = nsolve([Eq(0.56*(0.33*M_3a**2 + 1)**1.99/M_3a, 2.77), M_3a <= 1], 
[M_3a], 0.2)
print(eqn)

AttributeError: 'LessThan' object has no attribute 'diff'

Is nsolve able to compute with bounds?


On Thursday, February 11, 2021 at 11:26:15 PM UTC-5 mpierro3 wrote:

> Okay yeah, that was my main question as to whether Sympy had the 
> capability of doing so. Thanks! 
>
> On Thursday, February 11, 2021 at 6:14:34 PM UTC-5 Oscar wrote:
>
>> On Thu, 11 Feb 2021 at 22:54, mpierro3 <[email protected]> wrote:
>> >
>> > Yes, thank you. The rest is as follows:
>> >
>> > from sympy import *
>> > import numpy as np
>> >
>> > M_e = 1
>> > gamma_1 = 1.667
>> > gamma_4 = 1.667
>> > MW_1 = 39.948
>> > MW_4 = 4.0026
>> > D_4 = 5 / 39.37
>> > D_1 = 3 / 39.37
>> > A_4 = (np.pi / 4) * Pow(D_4, 2)
>> > A_1 = (np.pi / 4) * Pow(D_1, 2)
>> > a_4 = (gamma_4 + 1) / (gamma_4 - 1)
>> > a_1 = (gamma_1 + 1) / (gamma_1 - 1)
>> > A_4_A_1 = A_4 / A_1
>> >
>> > M_3a = symbols('M_3a', positive=true, nonzero=true)
>> > eqn = nonlinsolve([Eq((M_e / M_3a) * Pow((2 + (gamma_4 - 1) * Pow(M_3a, 
>> 2)) / \
>> > (2 + (gamma_4 - 1) * Pow(M_e, 2)), a_4 / 2), A_4_A_1), M_3a <= 1], M_3a)
>> > print(eqn)
>>
>> Your equation to be solved is (truncating the numbers for clarity):
>>
>> Eq(0.56*(0.33*M_3a**2 + 1)**1.99/M_3a, 2.77)
>>
>> I think it is unlikely that you will get analytic expressions for the
>> solutions to an equation like this.
>>
>> Sympy can solve it numerically though:
>>
>> In [31]: nsolve(eq[0], M_3a, 0.2)
>> Out[31]: 0.208399106769846
>>
>>
>> --
>> Oscar
>>
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/c3dc6738-993e-491c-b916-86531e204ecfn%40googlegroups.com.

Reply via email to