Group Abstract Group Abstract

Message Boards Message Boards

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

Implement an external function to a discretionary notebook?

Posted 8 years ago
Attachments:
POSTED BY: Epsilon Tau
3 Replies
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

Also, you can simplify your function quite a bit and make it not use any global variables with:

fehler2[exp_, vars_List] := 
 Sqrt[Plus @@ 
   Map[(D[exp, #]*ToExpression["\[CapitalDelta]" <> ToString[#]])^2 &,
     vars]]

which is used like this

fehler2[a*const + b*2, {a, b}]

Note that the variables are given as a list and not inlined in the function. You can make them inlined as you originally had but I think that is less conforming to Mathematica standards for functions:

fehler2[exp_, vars__] := 
 Sqrt[Plus @@ 
   Map[(D[exp, #]*
        ToExpression["\[CapitalDelta]" <> ToString[#]])^2 &, {vars}]]

which is called your old way:

fehler2[a*const + b*2, a, b]

You also have a big mistake in the way you use the function -- you must have the a,b,etc NOT defined as numbers when you call the function (in any of the versions). My suggestion is to do the following:

error = fehler[a*const + b*2, a, b]
error /. {a -> 1, b -> 2, const -> 9}

The same applies for fehler2 in either format. This approach will not define the a,b,const so you can change things without clearing anything in the kernel. Hope this helps.

Regards,

Neil

POSTED BY: Neil Singer

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
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard