Defining a function in Mathematica

  • Context: Mathematica 
  • Thread starter Thread starter nikolafmf
  • Start date Start date
  • Tags Tags
    Function Mathematica
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 reply · 3K views
nikolafmf
Messages
112
Reaction score
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?


Nikola
 
Physics news on Phys.org
I have already found out:

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

:D