Group Abstract Group Abstract

Message Boards Message Boards

0
|
5.3K Views
|
3 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Implement an external function to a discretionary notebook?

Posted 8 years ago

Hey guys, I've got a function which computes the propagation of uncertainty for a given function. It is called "fehler" and an example would be:

fehler[Sin[2*a], a]

which gives me

2 Sqrt[\[CapitalDelta]a^2 Cos[2 a]^2]

So basically the syntax is fehler[function, variable1, variable2,...]. The whole file is attached to the post, the credit goes to some random guy from my university, unluckily I could not figure out who made this function.

Now I'd like to make this function usable inside every notebook, because right now I always use it externally which is not really nice. So for example if i have a random notebook it should work like this:

(*random notebook*)
fehler= (*this is the code i need*)
a = 1; b=2; const=9;
fehler[a*const+b*2, a, b]
(*the output should like this*) Sqrt[const^2 \[CapitalDelta]a^2 + 4 \[CapitalDelta]b^2]

So that in every notebook I use i can simply use the "fehler"-function to calculate to propagation of uncertainty without having to use it globally. I tried to make this possible for a long time, but the main problem is that the existing fehler-function requires to clear all Variables with ClearAll["Global`*"]; before executing fehler. It is important that the output can be further used as a function, and not is simply a (numerical) result.

Do you guys have an idea how I can solve this problem? It would help me (and other students) a lot, if we could the function inside our notebooks and not externally.

Thanks you and best regards, Tobias

Attachments:
POSTED BY: Epsilon Tau
3 Replies

you can do a

NotebookEvaluate["Fehlerrechnung-gauss.nb"] 

if you delete the ClearAll and I suggest removing all the other extraneous evaluatable cells. This is simplest.

The "better" way to do this is to make a package out of it --Delete the ClearAll at the beginning and create a package:

You can load the package with

Needs["yourpackageName`"] 

(note the prime at the end of the name)

Regards,

Neil

POSTED BY: Neil Singer
POSTED BY: Neil Singer
Posted 8 years ago

Hey guys,

thanks a lot for your suggestions! I'll try it now and then tell you what I've achieved.

have a nice evening, Tobias

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