如何在 mathematica 中自动加载用户定义的函数 [英] how to automatically load user-defined functions in mathematica

查看:32
本文介绍了如何在 mathematica 中自动加载用户定义的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一堆在 mathematica 中经常使用的用户定义函数.我想知道我是否可以将它们存储在单独的文件中,mathematica 会在启动时加载它们并将它们视为内置函数,这样我就不必在创建新的 .nb 文件时重复定义.类似于 Matlab 中的函数...

I have a bunch of user-defined functions that are frequently used in mathematica. I wonder if I can store them in separate files and mathematica will load them on start and treat them as built-in functions, so that I don't have to repeat the definitions whenever I create a new .nb file. Something similar to functions in Matlab...

谢谢!

推荐答案

您可以在 $UserBaseDirectory/Autoload 中创建包.这将在内核初始化时加载.

You can create a package in $UserBaseDirectory/Autoload. This will be loaded at Kernel initialization time.

你的包应该有一个 Kernel/init.m 文件

Your package should have a Kernel/init.m file

MyPackage/Kernel/init.m

MyPackage/Kernel/init.m

有关 Mathematica 软件包的参考文档:http://reference.wolfram.com/mathematica/tutorial/SettingUpMathematicaPackages.html

Reference documentation on Mathematica packages: http://reference.wolfram.com/mathematica/tutorial/SettingUpMathematicaPackages.html

DeclarePackage[] 是符号及其定义的延迟加载机制.仅在使用符号时才加载关联的包:

DeclarePackage[] is a lazy loading mechanism for symbols and their definitions. The associated package is loaded only when the symbol is used:

http://reference.wolfram.com/mathematica/ref/DeclarePackage.html

这篇关于如何在 mathematica 中自动加载用户定义的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆