Message Boards Message Boards

Trouble defining a function

Posted 10 years ago

Hey Can someone tell what I do wrong? Above in line 20 i want to define a function f(x). And then i want to calculate f(2). But nothing happens. Why? Screenshot of my mathematica

3 Replies
Posted 10 years ago

"=" beginning a line sends the rest of the line to Mathematica displays the beginning "=" in orange to show the rest of the line was sent to does not understand or support function definitions.

Try the same without pressing "=" at the beginning of the line. That will send the line to Mathematica, which is different, and understands function definitions.

POSTED BY: Bill Simpson
Posted 10 years ago

Hi Bill

Thx for your answer, but I can not make it work. I am now trying to define a function in first line without starting with a "=". And then in next line i type ind f[1]. How do I make mathematica to respond and calculate f[1]=1+2?

screenshot mathematica

Posted 10 years ago

You are making progress. That is very good.

Here is what I enter into Mathematica

In[1]:= f[x_] := x + 1

In[2]:= f[2]

Out[2]= 3

In[3]:= f[a]

Out[3]= 1 + a

The In[ number ] := and Out[ number] = are supplied by Mathematica and I do not type those.

At the end of each line I press and hold Shift while pressing Enter. That tells Mathematica to do the work for that line. For the first line that just tells Mathematica to remember your definition and it displays nothing. For the second line you are asking it to calculate f[ 2 ] and it prints the third line of 3. The next two lines are similar.

I will try to attach a notebook that you may be able to download and read into Mathematica by double clicking on it or by opening Mathematica and then clicking File and then Open... and selecting the file from where it was downloaded to your computer.

If you have more questions then please ask and I will answer later today.

POSTED BY: Bill Simpson
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract