2
$\begingroup$

In the following, I would like to define a function $h(\theta, \beta, \alpha_1, \alpha_2)$. The function $h$ should be defined by the output of a previous function (which includes the partial derivative of a function $f(\theta,\beta,\alpha)$ with respect to $\theta$). The second line in the code below is:

g = D[Simplify[f[θ, β, α]], θ]

What I find is that I have to 'Copy As' the output of function $g$ as 'Input Text' in order for the defined function $h_2$ to yield a value (as opposed to $5\beta +4\theta$ as it currently yields) as I demonstrate at the bottom. Can anyone advise on how to associate the function definition of $h$ with the output of the function $g$ such that it yields a number when evaluated for say $\theta = 0, \beta = \pi/2, \alpha = \pi/3$?

This is the code in question:

f[θ_, β_, α_] := 2 θ^2 + 5 β*θ + 2 α^2 + 4 β*α

g = D[Simplify[f[θ, β, α]], θ]
(* 5 β + 4 θ *)

h[θ_, β_, α_] := g

h2[θ_, β_, α_] := 5 β + 4 θ

h[0., π/2, π/3]
(* 5 β + 4 θ *)

h2[0., π/2, π/3]
(* 7.85398 *)
$\endgroup$
1

1 Answer 1

3
$\begingroup$

Use Evaluate@g instead of just g.

f[θ_, β_, α_] := 2 θ^2 + 5 β*θ + 2 α^2 + 4 β*α
g = D[Simplify[f[θ, β, α]], θ]
h[θ_, β_, α_] := Evaluate@g

h[0., π/2, π/3]

5 β + 4 θ

7.85398
$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.