Message Boards Message Boards

Debugging issue in a function

Posted 11 years ago
Hi There!
I am new to Mathematica. One of my former colleagues coded a function in a .nb file, the function with six variables looks like the following: 
GRegressions[fileDirectory_, fileName_, \ incrementStop_, substrateToughness_, interfaceToughness_, dataCheck_, \ correctionFactor_] :=


Now, I am trying to call the function from another .nb file in the following way: 
GRegressions[ "/scratch/Example_Fracture/", "85deg_usubv101a.dat", 266, 10.0, 0.40, "yes", 1]; 


The main issue is I am not seeing any error message or anything else to work with. When I press Shift+Enter, it just doesn't show me anything. 
I would appreciate any of your advice about how can I proceed further?

Thank you so much!
-Rajib 
POSTED BY: Rajib Alam
6 Replies
Hi,

There are two possible reasons:
(1) there is mismatch in function argument patterns;
(2) the function was not loaded.

If all the arguments in the function definition have only Blank (_), then (1) is OK.
As for (2), you need to load the function by executing the function definition in the notebook that contains it. You can do it by clicking the mouse inside the cell with the function definition and by typing Shift+Enter. If you are using a recent version of Mathematica, the function name GRegressions in GRegressions[ "/scratch/Example_Fracture/", "85deg_usubv101a.dat", 266, 10.0, 0.40, "yes", 1] is in blue color if the function has not been loaded. It will turn to black once the function is loaded. The notebook can then be closed.

If the function will be repeatedly used, it is better to make a package. Then you can load the function using the command Get (<<). See Mathematica documentation for details.

Youngjoo Chung
POSTED BY: Youngjoo Chung
Safer to leave the first notebook open and use File menu - Open to locate and open the second notebook.
The two notebooks will share a Mathematica Kernel (the calculating engine) so all the definitions will be
shared as long as Mathematica front end and Kernel are running.
POSTED BY: Bruce Miller
Posted 11 years ago
Hi Bruce!

Yes, I think you are correct. I am sorry, I am the beginner of Mathmatica, I have some novice type of questions: a) How can I make sure if the second notebook has connection with the first one (the one with definition)? I kept  both files in the same directory; b) Should I close the definition one while I am running the second notebook? I closed the first one but still not seeing the output.

I highly appreciate your help.
-Rajib
POSTED BY: Rajib Alam
In the second notebook, evaluate
?GRegressions
to make sure the second notebook can see the definition from the first notebook.

My understanding is that you opened the notebook with the definition,
ran it, then opened the second notebook and tried to run it.  All this in the same
Mathematica Kernel session.  (You did not quit anything between creating the
function definition and using it, right?)
POSTED BY: Bruce Miller
Posted 11 years ago
Hello Youngjoo!

I removed the semicolon ";". It is showing me the same function Out[10] = GRegressions[ "/scratch/Example_Fracture/", "85deg_usubv101a.dat", 266, 10.0, 0.40, "yes", 1]. It is not showing the output of the function. I would like to see the output of the function. Could you please help me with this?

Many thanks!
-Rajib
POSTED BY: Rajib Alam
Hi,

Remove the semicolon (;) at the end and try again. The semicolon suppresses the output.

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

Group Abstract Group Abstract