ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 06 Dec 2021 00:36:56 +0100Manipulate dummy variable after solving trighttps://ask.sagemath.org/question/60108/manipulate-dummy-variable-after-solving-trig/Hi!
This might be somewhat basic, but is there a way to directly reference the dummy variable that pops up, when solving trigonometric functions?
sy(t)=sin(t)/2+7*sin(t/3)/2
sols=solve(sy(t)==0,t, to_poly_solve='force')
sols[0]
returns:
t == 3*pi + 6*pi*z27541
This dummy variable obviously changes every time the command is run, so there is no way of directly referencing it without changing the reference every time. Obviously this doesn't work:
sols[0](z=0)
The closest I have come, is just blindly referencing the variable which works if there are no other variables in the right hand side, like this:
sols[0].rhs()(0)
but this gives the obnoxious error message, that "*Substitution using function-call syntax and unnamed arguments is deprecated (...)*"
Is there a way to cleanly tell sage to evaluate an expression, when all z variables are 0 or 1 etc?jakuplMon, 06 Dec 2021 00:36:56 +0100https://ask.sagemath.org/question/60108/How to dynamically substitute a variable in a callable function?https://ask.sagemath.org/question/8825/how-to-dynamically-substitute-a-variable-in-a-callable-function/Hi guys, this is a little problem I came across a week ago.
I'm trying to define a python function that accepts:<br>
1. a callable sage function (of potentially more than one variable) as the first argument (henceforth called func), and <br>
2. a symbolic variable as the second argument (henceforth called xsub)
My function then needs to define a dummy symbolic variable (t), and substitute xsub with t in func. <br>I can do this for one variable equations in current 4.8 sagemath, by ignoring the new substitution syntax, but it throws up a depreciation warning (Which I'm assuming will become an error in 5.0).
Here's what my code looks like:
<pre>def fracintegral(func,xsub,n,a=0):
var('t')
assume(x>a)
assume(t>a)
return integrate((x-t)^(n-1)*func(t),t,a,x)</pre>
The last line should look something like:<pre>
return integrate((x-t)^(n-1)*func(x=t),t,a,x)</pre>
in order to avoid Depreciation Warnings, but this hardcodes x as the variable to be substituted. (Useless if my func is a y function.)
If I try:<pre>
return integrate((x-t)^(n-1)*func(xsub=t),t,a,x)</pre>
then substitution of func(x=t) doesn't occur (and the integrate function effectively treats func as a constant with respect to dt).
Trying:<pre>
return integrate((x-t)^(n-1)*func.subs(xsub==t),t,a,x)</pre>
doesn't work either, same result as func(xsub=t).
So, any idea how a function can accept a symbolic variable, and dynamically substitute out that variable in a callable function?JoalHeagneySat, 24 Mar 2012 21:51:48 +0100https://ask.sagemath.org/question/8825/