ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 11 Jul 2014 05:50:45 -0500Replace a variable with a functionhttps://ask.sagemath.org/question/23340/replace-a-variable-with-a-function/ Hello i hope anyone can help me with the following problem.
i have the following code
T_w,y,T_m,k_f,rho_f,U_0,h_mstar,R, alpha, delta, Phi = var('T_w y T_m k_f rho_f U_0 h_mstar R alpha delta Phi')
T=T_w+y*(-2*(T_w-T_m)/delta+rho_f*U_0*h_mstar*cos(Phi)/k_f)+y^2*((T_w-T_m)/delta^2-rho_f*U_0*h_mstar*cos(Phi)/(k_f*delta))
u=-6*U_0*R*y*(y-delta)*sin(Phi)/delta^3
integralTu=integrate(T*u,y,0,delta)
now i would like to differentiate integralTu with respect to x (diff(integralTu,x)), but delta must be a function of x (i first defined it as a variable because of the integration).Thu, 10 Jul 2014 07:42:14 -0500https://ask.sagemath.org/question/23340/replace-a-variable-with-a-function/Comment by slelievre for <p>Hello i hope anyone can help me with the following problem.</p>
<p>i have the following code</p>
<pre><code>T_w,y,T_m,k_f,rho_f,U_0,h_mstar,R, alpha, delta, Phi = var('T_w y T_m k_f rho_f U_0 h_mstar R alpha delta Phi')
T=T_w+y*(-2*(T_w-T_m)/delta+rho_f*U_0*h_mstar*cos(Phi)/k_f)+y^2*((T_w-T_m)/delta^2-rho_f*U_0*h_mstar*cos(Phi)/(k_f*delta))
u=-6*U_0*R*y*(y-delta)*sin(Phi)/delta^3
integralTu=integrate(T*u,y,0,delta)
</code></pre>
<p>now i would like to differentiate integralTu with respect to x (diff(integralTu,x)), but delta must be a function of x (i first defined it as a variable because of the integration).</p>
https://ask.sagemath.org/question/23340/replace-a-variable-with-a-function/?comment=23372#post-id-23372@tetraeder, @kcrisman: add tags?Fri, 11 Jul 2014 05:50:45 -0500https://ask.sagemath.org/question/23340/replace-a-variable-with-a-function/?comment=23372#post-id-23372Answer by kcrisman for <p>Hello i hope anyone can help me with the following problem.</p>
<p>i have the following code</p>
<pre><code>T_w,y,T_m,k_f,rho_f,U_0,h_mstar,R, alpha, delta, Phi = var('T_w y T_m k_f rho_f U_0 h_mstar R alpha delta Phi')
T=T_w+y*(-2*(T_w-T_m)/delta+rho_f*U_0*h_mstar*cos(Phi)/k_f)+y^2*((T_w-T_m)/delta^2-rho_f*U_0*h_mstar*cos(Phi)/(k_f*delta))
u=-6*U_0*R*y*(y-delta)*sin(Phi)/delta^3
integralTu=integrate(T*u,y,0,delta)
</code></pre>
<p>now i would like to differentiate integralTu with respect to x (diff(integralTu,x)), but delta must be a function of x (i first defined it as a variable because of the integration).</p>
https://ask.sagemath.org/question/23340/replace-a-variable-with-a-function/?answer=23344#post-id-23344You are right that Maxima doesn't want delta to be a function, since it's a limit of integration. That was slightly surprising to me.
Anyway, it turns out you can fix this post-hoc.
sage: integralTu.subs(delta=function('delta',x))
1/10*(2*U_0*h_mstar*rho_f*cos(Phi)*delta(x)^4 + 7*T_m*k_f*delta(x)^3 + 3*T_w*k_f*delta(x)^3)*R*U_0*sin(Phi)/(k_f*delta(x)^3)
That might seem a little hackish, but is just fine.
sage: IT = integralTu.subs(delta=function('delta',x))
sage: diff(IT,x)
1/10*(8*U_0*h_mstar*rho_f*cos(Phi)*delta(x)^3*D[0](delta)(x) + 21*T_m*k_f*delta(x)^2*D[0](delta)(x) + 9*T_w*k_f*delta(x)^2*D[0](delta)(x))*R*U_0*sin(Phi)/(k_f*delta(x)^3) - 3/10*(2*U_0*h_mstar*rho_f*cos(Phi)*delta(x)^4 + 7*T_m*k_f*delta(x)^3 + 3*T_w*k_f*delta(x)^3)*R*U_0*sin(Phi)*D[0](delta)(x)/(k_f*delta(x)^4)
By the way, I've updated your question because you needed one more variable defined.Thu, 10 Jul 2014 08:42:17 -0500https://ask.sagemath.org/question/23340/replace-a-variable-with-a-function/?answer=23344#post-id-23344Comment by tetraeder for <p>You are right that Maxima doesn't want delta to be a function, since it's a limit of integration. That was slightly surprising to me.</p>
<p>Anyway, it turns out you can fix this post-hoc.</p>
<pre><code>sage: integralTu.subs(delta=function('delta',x))
1/10*(2*U_0*h_mstar*rho_f*cos(Phi)*delta(x)^4 + 7*T_m*k_f*delta(x)^3 + 3*T_w*k_f*delta(x)^3)*R*U_0*sin(Phi)/(k_f*delta(x)^3)
</code></pre>
<p>That might seem a little hackish, but is just fine.</p>
<pre><code>sage: IT = integralTu.subs(delta=function('delta',x))
sage: diff(IT,x)
1/10*(8*U_0*h_mstar*rho_f*cos(Phi)*delta(x)^3*D[0](delta)(x) + 21*T_m*k_f*delta(x)^2*D[0](delta)(x) + 9*T_w*k_f*delta(x)^2*D[0](delta)(x))*R*U_0*sin(Phi)/(k_f*delta(x)^3) - 3/10*(2*U_0*h_mstar*rho_f*cos(Phi)*delta(x)^4 + 7*T_m*k_f*delta(x)^3 + 3*T_w*k_f*delta(x)^3)*R*U_0*sin(Phi)*D[0](delta)(x)/(k_f*delta(x)^4)
</code></pre>
<p>By the way, I've updated your question because you needed one more variable defined.</p>
https://ask.sagemath.org/question/23340/replace-a-variable-with-a-function/?comment=23345#post-id-23345Thanks, it works!Thu, 10 Jul 2014 08:53:46 -0500https://ask.sagemath.org/question/23340/replace-a-variable-with-a-function/?comment=23345#post-id-23345