Ask Your Question

bob323's profile - activity

2020-06-08 22:24:47 +0200 received badge  Popular Question (source)
2020-06-08 22:24:47 +0200 received badge  Notable Question (source)
2018-06-21 14:55:52 +0200 received badge  Supporter (source)
2018-06-21 14:55:50 +0200 received badge  Scholar (source)
2018-06-21 14:14:17 +0200 received badge  Student (source)
2018-06-20 22:33:54 +0200 asked a question How to substitute values for derivatives?

I would like to first differentiate a function, then substitute values for derivatives within the function.

For example, a function might be cos(theta)*sin(phi). I would like to differentiate with respect to another variable (time in this case):

sage: t = var('t')
sage: theta = function('theta')(t)
sage: phi = function('phi')(t)
sage: A = cos(theta)*sin(phi)
sage: C = diff(A,t,t)
sage: C
-cos(theta(t))*sin(phi(t))*diff(phi(t), t)^2 - 2*cos(phi(t))*sin(theta(t))*diff(phi(t), t)*diff(theta(t), t) - cos(theta(t))*sin(phi(t))*diff(theta(t), t)^2 + cos(phi(t))*cos(theta(t))*diff(phi(t), t, t) - sin(phi(t))*sin(theta(t))*diff(theta(t), t, t)
sage: C.subs(theta=5,phi=6,diff(theta(t),t)=7,diff(phi(t),t)=8,diff(theta(t),t,t)=9,diff(phi(t),t,t)=10)
  File "<ipython-input-147-f1b68bf72320>", line 1
SyntaxError: keyword can't be an expression

I believe the error comes from trying to define the entire function theta(t), diff(phi(t),t,t), etc. as a single number. It should work just as well to substitute other variables in the place of the derivatives; I only want the derivatives there for getting the initial equations. Is there a way to either:

  1. Define each derivative to be a specific value and evaluate the expression, or
  2. Substitute variables for derivatives, which can in turn be substituted with values and the expression evaluated?