On Tue, Sep 16, 2008 at 3:56 PM, Jason Grout
<[EMAIL PROTECTED]> wrote:
>
> I'm writing an @interact to solve simple 2nd order differential
> equations and plot solutions. In it, I'd like to typeset the formula:
>
> show(a*diff(y,t,2)+b*diff(y,t)+c==0)
>
> However, what shows up is the word "diff" when I'd really like to see
> math notation for a partial or total derivative (depending on the
> independent variables declared for y). Is there a nice way to get it to
> show up?
>
> Note that just printing a string doesn't work so well, since a, b, or c
> might be negative and then you get something like
> 3(d^2y/dt^2)+-2(dy/dt)+-3=0.
>
> For reference, the current (non/barely) working code is:
>
> var("x,t")
> @interact
> def _(y0=(0,4,1/5), y0p=(0,4,1/5),a=(-4,4,1/5),b=(-4,4,1/5),c=(-4,4,1/5)):
> y=function('y',t)
> show(a*diff(y,t,2)+b*diff(y,t)+c==0)
Though ugly to input, I would be tempted to do something like this,
since the output looks superb:
a = sin(x); y = cos(x^2) + e^(3*pi*x)
html("$$%s \cdot \\frac{d^2}{dt^2}\\left[ %s \\right]$$"%(latex(a), latex(y)))
> show(" y(0)=%s, y'(0)=%s"%(y0,y0p))
> t0=0
> discriminant = sqrt(b^2-4*a*c)
> if discriminant > 0:
> r1 = (-b+discriminant)/(2*a)
> r2 = (-b-discriminant)/(2*a)
> c1=(y0p-y0*r1)/(r1-r2)*e^(-r1*t0)
> c2=(y0*r1-y0p)/(r1-r2)*e^(-r2*t0)
> soln = c1*e^(r1*t)+c2*e^(r2*t)
> show(soln)
> plot(soln,(t,0,5)).show()
>
>
> Thanks,
>
> Jason
>
>
> >
>
--
William Stein
Associate Professor of Mathematics
University of Washington
http://wstein.org
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---