2009/4/3 Brian <medo...@gmail.com>: > > Indeed, thanks William. I'm not understanding the problem though, as > range works with "ordinary" variables: > > x=5 > [t for t in range(1,x)]
Here x "is" (or rather -- points to) the constant integer 5. It's not a symbolic variable. If you do x = var('x') then x is a symbolic variable. > > Anyway, I changed the units function to not use a list comprehension, > and instead use this formula: > http://i.investopedia.com/inv/tutorials/site/advancedbond/yield9.GIF > > The new units function: > def units(C, n, F, r): > return C * ((1 - (1 / (1 + r) ^ n)) / r) + F * (1 / (1 + r) ^ n) > > And here we have arrived, successful, with the 3d plot expression: > > plot3d(price(70,var('n'),1000,var('r')), (n,1,5), (r,0,5)) > > Hooray sage! Very cool. > > On Apr 3, 8:53 pm, William Stein <wst...@gmail.com> wrote: >> On Fri, Apr 3, 2009 at 7:45 PM, Brian <medo...@gmail.com> wrote: >> >> > Thank you Timothy. Here is the correct (I believe) code for that >> > equation. >> >> > def units(C, n, F, r): >> > return sum([C / (1 + r) ^ t for t in range(1, n+1)]) + F / (1 + r) >> > ^ n >> >> > def price(C, n, F, r): >> > return 100 * (units(C, n, F, r) / F) >> >> > Here, units expresses the equation I linked to, and price gives the >> > scaled price, 100 being par. >> >> > For example, evaluating the expression below demonstrates the example >> > calculation from this site: >> >http://www.moneychimp.com/articles/finworks/fmbondytm.htm >> >> > units(70,4,1000,.0853) >> >> > That evaluates to ~950 as in the example, therefore giving a price of >> > ~95: >> >> > price(70,4,1000,.0853) >> >> > And sure enough, plotting the price yield curve gives sensible >> > results: >> > plot(price(70,4,1000,var('y')),0,.2) >> >> > Now I would like to make a 3d plot where n and r are free. The >> > trouble is, when I try it, I get the following error. Would someone >> > point out my error? >> >> > plot(price(70,var('n'),1000,var('y'))) >> >> > TypeError: range() integer start argument expected, got >> > sage.rings.integer.Integer. >> >> The problem is that you're giving the symbolic variable "n" as input >> to the range command (in your units function), but the range command >> takes a pair of integers as input. >> >> William > > > -- William Stein Associate Professor of Mathematics University of Washington http://wstein.org --~--~---------~--~----~------------~-------~--~----~ 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 URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---