TransWikia.com

Save a Derivative

Mathematica Asked by Brett van de Sande on February 23, 2021

I have defined the derivative of a function

Derivative[1][f][x_] := Sin[x]

How can I save this definition in a file? Derivatives are not included in FullDefinition[f], so Save["file.m",f] won’t work. The best I can do now is

WriteLine["file.m","Derivative[1][f][x_] := Sin[x]"]

Any ideas how to do this more properly?

2 Answers

I did not fully understand the intention, it looks like you are trying to assign a function to an operator. If you use the name df the following works:

df[x_] := Sin[x]
(* save *)
Export["/tmp/test.wdx", df[x]]
(* clear *)
Clear@df
(* load *)
df[x_] := Evaluate@Import["/tmp/test.wdx"]

Answered by kloppy on February 23, 2021

This works for me:

ClearAttributes[Derivative, {ReadProtected}]
Derivative[1][f][x_] := Sin[x]
Save["file.m", {f, Derivative}]

Edit

Included the line that clears the ReadProtected attribute, in case it's necessary. It seems like this might depend on version or something, because for me Derivative never has that attribute in a new kernel.

Answered by Sjoerd Smit on February 23, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP