Mathematica Asked on April 12, 2021
I’m coding my first physics simulation in Mathematica, and have a problem. I want to do the following inside a single cell input.
Clear[x, y]
F[x_, y_] := Cos[x] Cos[y];
!(
*SubscriptBox[([PartialD]), (x)](F[x, y]))
Then I click shift enter and copy output -Cos[y] Sin[x] to the next cell as the deffinition of G[x,y].
G[x_, y_] := -Cos[y] Sin[x];
Print[{G[a, b], G[c, d], G[e, f]}]
Note, that above was only an example. The code should work for any differentiable function F[x,y].
Also, I want the code to do differentiation only once, because G[x,y] will then be evaluated tens of millions of times.
This works for me on V 12.1 on windows
Clear[x, y, F, G]
F[x_, y_] := Cos[x] Cos[y];
G[x_, y_] := D[F[x, y], x];
{G[x, y], G[c, f], G[e, f]}
If I were you, I'd avoid UpperCase single letters. I would also avoid using the math input palettes to enter derivatives and so on and get used to using plain text Mathematica commands, so you get used to them instead of just clicking on a symbol. But this is just me.
So instead of
I would write
Because I want to see the command itself in plain text and also I might want to later save the code as plain text file (.m).
Answered by Nasser on April 12, 2021
We can also use Derivative
act on the function F to get a pure function and then Apply
to another variables.
Clear["`*"];
F[x_, y_] := Cos[x] Cos[y];
G=Derivative[1, 0][F]
(* -Cos[#2] Sin[#1]& *)
G@@@ {{a, b}, {c, d}, {e, f}, {s, t}, {u, v}, {x, y}}
(* {-Cos[b] Sin[a],-Cos[d] Sin[c],-Cos[f] Sin[e],-Cos[t] Sin[s],-Cos[v] Sin[u],-Cos[y] Sin[x]} *)
Answered by cvgmt on April 12, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP