Defining a function in Mathematica

  • #1
114
0
Hello,

I know that in Mathematica one can define a function as follows:

f[x_]:=x^2.

The problem is, I get a polynomial from a for loop as an expression p=a*x^n+b*x^(n-1)+.... Now I want to evaluate the polynomial at a specific point. I tried to define a function from the polynomial as follows:

f[x_]:=p

and to evaluate

f[2]

which gives me just the polynomial, not it's value at 2.

How can I evaluate this?

Sincerely,
Nikola
 

Answers and Replies

  • #2
114
0
I have already found out:

f = Function[k, p /. x -> k]

:D
 

Related Threads on Defining a function in Mathematica

Replies
3
Views
2K
Replies
2
Views
2K
Replies
1
Views
7K
Replies
4
Views
5K
Replies
3
Views
21K
Replies
2
Views
3K
Replies
4
Views
661
Top