[sage-support] noob q: solve in loop doesn't iterate each time

2011-09-07 Thread Chipslinger
I've been messing around with using Sage for solving node equations. I
have the right syntax and structure for creating and symbolically
solving equations, but am struggling with:
* Using solve in a loop -- it doesn't evaluate using new
parameters each time through
* Printing in decimal format -- I've tried using N(x, digits=4),
but can't get it to work with the result from solve; I get lots of
errors

Here's a simple program I tried last night (using sagenb.org version
4.7):

# Schmitt Trigger Threshold Calculation
var('rtop, rbot, rfd, rout_pullup, vnode, vcc, vin, vthresh')
rtop = 1
rbot = 1
rout_pullup = 1
rfd = 1e6
vin = 5
#vcc = 5
eq1 = (vin-vnode)/rtop + (vcc-vnode)/(rout_pullup+rfd) == vnode/rbot
out_states = [0, 5]
for i in range(2):
vcc = out_states[i]
vthresh = solve([eq1], vnode)
print '%4s: %4s'%(vcc, vthresh)

Any help or pointers towards relevant docs would be greatly
appreciated. Thank you in advance.

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


Re: [sage-support] noob q: solve in loop doesn't iterate each time

2011-09-07 Thread Rajeev Singh
On Wed, Sep 7, 2011 at 7:31 PM, Chipslinger cbol...@boltoneng.com wrote:
 I've been messing around with using Sage for solving node equations. I
 have the right syntax and structure for creating and symbolically
 solving equations, but am struggling with:
    * Using solve in a loop -- it doesn't evaluate using new
 parameters each time through
    * Printing in decimal format -- I've tried using N(x, digits=4),
 but can't get it to work with the result from solve; I get lots of
 errors

 Here's a simple program I tried last night (using sagenb.org version
 4.7):

 # Schmitt Trigger Threshold Calculation
 var('rtop, rbot, rfd, rout_pullup, vnode, vcc, vin, vthresh')
 rtop = 1
 rbot = 1
 rout_pullup = 1
 rfd = 1e6
 vin = 5
 #vcc = 5
 eq1 = (vin-vnode)/rtop + (vcc-vnode)/(rout_pullup+rfd) == vnode/rbot
 out_states = [0, 5]
 for i in range(2):
    vcc = out_states[i]
    vthresh = solve([eq1], vnode)
    print '%4s: %4s'%(vcc, vthresh)

 Any help or pointers towards relevant docs would be greatly
 appreciated. Thank you in advance.

 --
 To post to this group, send email to sage-support@googlegroups.com
 To unsubscribe from this group, send email to 
 sage-support+unsubscr...@googlegroups.com
 For more options, visit this group at 
 http://groups.google.com/group/sage-support
 URL: http://www.sagemath.org




How about this -


# Schmitt Trigger Threshold Calculation
var('rtop, rbot, rfd, rout_pullup, vnode, vcc, vin, vthresh')
rtop = 1
rbot = 1
rout_pullup = 1
rfd = 1e6
vin = 5
#vcc = 5
eq1 = (vin-vnode)/rtop + (vcc-vnode)/(rout_pullup+rfd) == vnode/rbot
out_states = [0, 5]
vthresh = solve([eq1], vnode)[0].rhs()
for i in range(2):
   vcc = out_states[i]
   print '%4s: %.4f'%(vcc, vthresh.substitute(vcc=vcc).n())

output is -
0: 2.4877
5: 2.5123


I have done very small changes in your code. Hope it helps.

Rajeev

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org