Group Abstract Group Abstract

Message Boards Message Boards

0
|
1.7K Views
|
3 Replies
|
0 Total Likes
View groups...
Share
Share this post:

How to define a function as an operation on the other option

Posted 3 years ago

In the attached file, I defined the function f as $ f(x,y,z) = x^2 + y^2 + z^2$ and then I tried to define the function g as the Laplacian of the function f as the Laplacian of the function f. However, as shown in the attached file, it doesn't generate g[1,1,1].
Any help would be appreciated.

Attachments:
POSTED BY: Hossein Khani
3 Replies
Posted 3 years ago

You can constrain the arguments to be symbols, or you can use ReplaceAll, or us a scoping construct to "localize" the formal variables (or some combination). Not sure if this is the best way, but something to start/play with:

g[x_, y_, z_] := 
  Module[{x1, y1, z1}, Laplacian[f[x1, y1, z1], {x1, y1, z1}] /. {x1 -> x, y1 -> y, z1 -> z}]
POSTED BY: Eric Rimbey
Posted 3 years ago

Actually, this is overkill. You could just evaluate the Laplacian immediately:

g[x_, y_, z_] = Laplacian[f[x, y, z], {x, y, z}]
POSTED BY: Eric Rimbey
Posted 3 years ago

I think you used x in place of z in your definition of g:

Laplacian[x^2 + y^2 + z^2, {x, y, x}]

Shouldn't it be:

Laplacian[x^2 + y^2 + z^2, {x, y, z}]

?

But even after that fix, I think you're still going to have a problem. When you try to evaluate g[1,1,1] it will do all of the argument replacements first, and you'll end up with Laplacian[3, {1, 1, 1}].

POSTED BY: Eric Rimbey
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard