Mathematica: A function that derives another function on all its arguments

In summary, the conversation is about creating a function in Mathematica that takes in another function g and returns the sum of g's derivatives with respect to its arguments multiplied by a scalar Δxi. The solution involves using the built-in D function and the Table function to create a list of variables and calculate the derivatives.
  • #1
shfreeman
2
0
Hi!

I am wondering if someone could help me write a function in Mathematica. What I would like it to do is take another function g
as its argument and return the sum of g derived to all of its arguments (and multiplied by a scalar Δxi)

[tex] f\left[g\left[x_1,x_2,\text{...},x_n\right]\right] = \sqrt{\overset{n}{\sum _{i=1} }\left(\frac{\partial g}{\partial x_i}\text{$\Delta $x}_i\right){}^2} [/tex]

I have already managed to make such a function by brute force,
but it brakes down if I assign a value to any character (a,b,c,d,...). This is what I came up with:

[tex] \text{symbols}=\{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,\text{Ee},F,G,H,\text{Ii},J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,\alpha ,\beta ,\gamma ,\delta ,\varepsilon ,\zeta ,\eta ,\theta ,\iota ,\kappa ,\lambda ,\mu ,\nu ,\xi ,o,\rho ,\varsigma ,\sigma ,\tau ,\upsilon ,\varphi ,\chi ,\psi ,\omega \}; [/tex]
[tex] \text{abs}[\text{f$\_$}]\text{:=} \surd \text{Sum}\left[(D[f,\text{symbols}[[\aleph ]]]*\text{Symbol}[\Delta <>\text{ToString}[\text{symbols}[[\aleph ]]]])^2,\{\aleph ,\text{Length}[\text{symbols}]\}\right. [/tex]

I hope someone can help me come up with a better solution.

Thanks!
 
Physics news on Phys.org
  • #2


Hi!

I would be happy to help you with this. Mathematica has a built-in function called D that can take derivatives of functions with respect to their arguments. We can use this to create a function that takes in another function g and returns the sum of its derivatives with respect to all of its arguments multiplied by a scalar Δxi. Here is the code for the function:

f[g_] := Sqrt[Sum[(D[g @@ Table[x, {i, n}], x]*Δx)^2, {i, n}]]

This function takes in a function g and uses the Table function to create a list of variables x with i ranging from 1 to n. Then, it uses the D function to take the derivative of g with respect to each of these variables and multiplies it by the corresponding scalar Δxi. Finally, it returns the square root of the sum of these squared derivatives.

To use this function, you can simply input your desired function g as an argument. For example, if you wanted to use the function with the expression x^2 + y^2, you would input f[x^2 + y^2]. You can also specify the value of n (the number of arguments) and the values of Δxi by using the Table function and assigning them to x and Δx, respectively.

I hope this helps! Let me know if you have any further questions or if you would like me to explain the code in more detail. Happy coding!
 

Related to Mathematica: A function that derives another function on all its arguments

What is Mathematica?

Mathematica is a software program used for mathematical and scientific computing. It allows users to perform complex calculations, create visualizations, and write programs or functions.

What is a function in Mathematica?

In Mathematica, a function is a set of instructions or rules that take in input values and produce an output value. It can be used to perform operations, manipulate data, or solve problems.

How do you create a function in Mathematica?

To create a function in Mathematica, you can use the "Function" or "DefineFunction" command. This allows you to define the input parameters, specify the operations or calculations to be performed, and return the output value.

Can a function in Mathematica take in another function as an input?

Yes, a function in Mathematica can take in another function as an input. This is known as a higher-order function, and it allows for more complex and versatile programming capabilities.

What is "deriving a function" in Mathematica?

In Mathematica, "deriving a function" refers to the process of creating a new function that is based on another function. This can be done by manipulating the original function's input parameters, output values, or both.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
6K
  • Classical Physics
Replies
1
Views
482
  • Advanced Physics Homework Help
Replies
8
Views
935
Replies
1
Views
752
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • Introductory Physics Homework Help
Replies
4
Views
239
Replies
2
Views
1K
Replies
21
Views
2K
Back
Top