Group Abstract Group Abstract

Message Boards Message Boards

0
|
10.2K Views
|
5 Replies
|
0 Total Likes
View groups...
Share
Share this post:

[?] Define the output of a function as a new function?

Posted 8 years ago

Hey Guys!

I've got the following problem. I have the function

f[a_,b_,c_]=a+b/c

Now I'd like to set a new function

g[a_,b_,c_]=D[f[a_,b_,c_],a_]

So the plan would be to have a new function which I can use to compute g for different a,b,c. For example I'd say a=1 b=2 c=3 and Mathematica would tell me g. Obviously it does not work because i have the same variables on the right and on the left side. I've already googled my brain away but I found no solution. Do you have some advice for me?

I am sorry if I formatted something wrong, this is my first activity in the Wolfram community.

Thanks, Tobias

POSTED BY: Epsilon Tau
5 Replies
Posted 8 years ago

Hey,

thanks for your answers, I read the articles and was able to solve a half of the actual problem, which is the following:

I have the function

El[k_ , l_, d_] := k * l / (0.25*d^2*Pi)

and computed the gaussian variance formula

Eld [k_, l_, d_, kd_, ld_, dd_] := 
 Sqrt[kd (Derivative[1, 0, 0][El])^2 + 
   ld (Derivative[1, 0, 0][El])^2 + dd (Derivative[1, 0, 0][El])^2]

It works pretty well for El... El[1,2,3] gives me 0.282942.

However, Eld[1, 2, 3, 4, 5, 6] doesn't work, which makes sense because Eld can't give k,l and d to El. However, I do not know how to solve this problem. Can you help me again?

Thank you,

Tobias

POSTED BY: Epsilon Tau

To understand what is happening, you should read:

I noticed you used a_, with the _ on the right hand side of a definition. This is wrong. a_ is a pattern and a is the name of that pattern. The pattern should appear only on the left hand side. Please read:

Finally, the easiest way to solve this problem is to use Derivative (look it up!):

g = Derivative[1,0,0][f]
POSTED BY: Szabolcs Horvát

We don't know what you want to do, so you might either need = or := depending on what you want to do. If a, b and, c are numbers, the derivative does not make any sense, you can't do the derivate with respect to a number...

POSTED BY: Sander Huisman
Posted 8 years ago

This works, but if i define a,b and c it's not working anymore.

POSTED BY: Epsilon Tau

I think you want this:

ClearAll[f, g]
f[a_, b_, c_] := a + b/c
g[a_, b_, c_] = D[f[a, b, c], a]

you can now check the definition of g:

??g

giving

g[a_,b_,c_]=1

as expected...

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