2

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 *)

Domen
  • 23,608
  • 1
  • 27
  • 45
John Doe
  • 371
  • 1
  • 11
  • Or use = instead of :=. Relevant: https://mathematica.stackexchange.com/questions/8829/what-is-the-difference-between-set-and-setdelayed – Goofy Dec 25 '23 at 00:09

1 Answers1

3

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

azerbajdzan
  • 15,863
  • 1
  • 16
  • 48