Ask Your Question

duke11235's profile - activity

2019-03-19 17:48:35 -0600 received badge  Notable Question (source)
2019-03-19 17:48:35 -0600 received badge  Popular Question (source)
2017-04-19 20:49:20 -0600 received badge  Popular Question (source)
2014-06-29 14:01:54 -0600 received badge  Famous Question (source)
2014-06-29 14:01:54 -0600 received badge  Popular Question (source)
2014-06-29 14:01:54 -0600 received badge  Notable Question (source)
2012-09-04 08:24:34 -0600 asked a question Simplify to real and positive numbers
eng8 = [solve(eng==(k-1)*md*Vm1^2/(2*Patm*Vs*((Pc-(P2*s6))-(Pc-(P2*s6))^(1/k))),Vm1) for s6 in srange(r9,r10,s5,include_endpoint=1)]
v4=[v[0].rhs().n() for v in eng8]
v5=[v for v in v4 if v >= 0]

I can't seem to get v5 to output both real and positive numbers, only an empty list. All the inputs are positive, and I know the square root of the squared gives both positive and negative output. Any help?

2012-08-30 10:12:25 -0600 commented answer Gas Law Symbolic Equation

Thanks. That clears it right up.

2012-08-30 10:11:59 -0600 marked best answer Gas Law Symbolic Equation

The first step in debugging is to look to see what the first argument actually is. I'm assuming that you did n = var("n") or something at some point. So we can get the first element:

sage: Pps = np.arange(103421.359,1013529,6895.75729) 
sage: Pps[0]
sage: Pp = Pps[0]
sage: Pp * Vt
sage: Pp * Vt == n
sage: Pp * Vt == n*r*t

.. and we see that Sage is automatically evaluating the expression, and since it can't prove that it's true -- which is good, because it's not true in general -- it's saying that it's False.

Ultimately this is because

sage: type(Pp)
<type 'numpy.float64'>

Pp is a numpy float, which doesn't interact too well with the Sage types. As soon as the __eq__ method of the float is called, the game's over. You can work around this in some fragile ways, such as flipping the order:

sage: n*r*t == Pp*Vt  
2446.62193200810*n == 144.055610951
sage: solve(n*r*t == Pp*Vt, n)
[n == (52361895020038/889307677165161)]

But a better and more robust way would be to avoid getting numpy involved at all, and stick with Sage-native objects. For example, you can use srange and sxrange:

srange(start, end=None, step=1, universe=None, check=True, include_endpoint=False, endpoint_tolerance=1e-05)
    Return list of numbers ``a, a+step, ..., a+k*step``,
    where ``a+k*step < b`` and ``a+(k+1)*step >= b`` over
    exact rings, and makes a best attempt for inexact rings 
    (see note below).

which would give:

sage: s = srange(103421.359,1013529,6895.75729)
sage: len(s)
sage: s[:5]
[103421.359000000, 110317.116290000, 117212.873580000, 124108.630870000, 131004.388160000]

and then

sage: eng5= [solve(Pp*Vt == n*r*t,n) for Pp in srange(103421.359,1013529,6895.75729)]
sage: len(eng5)
sage: eng5[:3]
[[n == (52361895020038/889307677165161)], [n == (56778965120683/904048017111831)], [n == (74168281138961/1111449736506101)]]

Short version: don't use numpy unless you need to, and here you don't.

2012-08-30 08:33:26 -0600 commented answer Gas Law Symbolic Equation

Could you elaborate on when one might use srange, xrange or np.arange? Why did someone request using np.arange on this problem: I see that srange() works there, but xrange() does not. Is it because srange and np.arange both generate a list output, but xrange does it dynamically? Thanks for the clarification!

2012-08-30 07:42:36 -0600 asked a question Gas Law Symbolic Equation

Ideal Gas Law[Relates Pressure and Volume]

Definitions v3

#Main Tank Pressure[Pascals]
#Tank Volume[m^3]
#Moles of Air
#n= 0
#Gas Constant
#Ambient Temperature[Kelvin][70F]
t= 294.261
eng5= [solve(Pp*Vt == n*r*t,n) for Pp in np.arange(103421.359,1013529,6895.75729)]

Why does this say:

TypeError: The first argument must be a symbolic expression or a list of
symbolic expressions.

I have the variables defined elsewhere[Pp =var('Pp')] but I'm not sure why this won't work. Thanks

2012-08-30 07:36:45 -0600 commented answer Unexpected solve() errors

That works pretty well, but with 0 as the start it throws an empty list, which screws up my list comprehension. It works pretty well. Do you know about the other problem or why

2012-08-29 16:45:30 -0600 received badge  Editor (source)
2012-08-29 16:43:08 -0600 asked a question Unexpected solve() errors
#Area [m^2]
Ab = 0.00313659226
#CB Ratio
cb = 0.262
eng4 =[solve(cb == Vc/(Ab*Lb),Lb) for Vc in xrange(0.000001,0.00002)]

This returns an empty list [] and I have no idea why. And this one:

#Ideal Gas Law[Relates Pressure and Volume]
#Definitions v3
#Main Tank Pressure[Pascals]
#Tank Volume[m^3]
#Moles of Air
#Gas Constant
#Ambient Temperature[Kelvin][70F]
t= 294.261

eng5= solve(Pp*Vt == n*r*t,n,solution_dict=1)

__main__:18: DeprecationWarning: Substitution using function-call syntax and unnamed arguments is deprecated and will be removed from a future release of Sage; you can use named arguments instead, like EXPR(x=..., y=...) See for details. 75589949342674/131001015929725

Or it just shows the fraction. It's been acting weird lately


2012-08-29 10:38:03 -0600 marked best answer What's Wrong With This?

Your solve syntax has two minor problems. First, Sage uses == for equality, not =, and second, the parentheses aren't balanced. You're missing ")". After correcting these:

sage: solve(eng==(k-1)*md*Vm^2/(2*Patm*Vc*(Pc-Pc^(1/k))),Vc)                           
[Vc == (1821842000000/164304225615681)]
2012-08-29 10:38:03 -0600 received badge  Scholar (source)
2012-08-28 10:55:37 -0600 asked a question What's Wrong With This?
#Pneumatic Air Gun Calculations
import matplotlib.pyplot as plt

#Variables Outlined

#Muzzle Velocity
#Atmospheric Pressure
#Gas Chamber Volume
#Barrel Area[Internal]
#Barrel Length
#Specific Heat of Air
#CB Ratio[see table]
#formula variable
#2nd Formula Variable
#Mass of the Projectile
#Operating Pressure in atm

k = 1.4
Patm = 101235
cb = 0.261208
Vm= 91.44

#Main Formula

Can anyone tell me why this is giving a syntax error and pointing to my variable definition Vm? It's really bugging me!