Can I find constants in a function?

Let’s say, I have a function with a constant, e.g. y(x)=x+cy(x)=x+cy(x)=x+c, and a condition y(0)=5y(0)=5y(0) = 5.
I want to type in something like Solve[{y[x]=x+c, y[0] =5}, {c}] and get the value of a constant. Is there a way to do it in Mathematica or Wolfram Alpha?



3 Answers


You can define your function, to use your example:

y[x_] := x + c

and then simple solve it using the initial condition:

In[10]:= Solve[y[0] == 5, c]

Out[11]= {{c -> 5}}

The title of your question is a bit confusing, since this doesn’t really have much to do with ODEs. 🙂



I was working with ODEs, but I totally agree with you, changed the title and the question
– ivt
Sep 16 ’14 at 19:03

you can enter y(0)=2 for example enter:
i think this is solve your problem.
this is for online mathmatica(



It will use some kind of DSolve under the hood. I don’t need to solve the ODE, I already have the general solution
– ivt
Sep 15 ’14 at 20:37

It is worth mentioning DSolve works similarly to Solve, and that NSolve will give you a numerical representation of a number rather than a symbolic. for example, say I want to find the roots of x2−2=0x^{2} – 2 = 0

Solve[x^2 – 2, x] == 0

will return √2,−√2\sqrt{2}, -\sqrt{2}, but NSolve will return

{{x -> -1.41421}, {x -> 1.41421}}

Also, I think DSolve uses Solve under the hood, not the other way around