# Can I find constants in a function?

Let's say, I have a function with a constant, e.g. $y(x)=x+c$, and a condition $y(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?

• Do you mean $y \color{red}{'}(x)=x+c$ (otherwise it's not a DE)?
– alexqwx
Sep 15, 2014 at 20:34
• Yeah, I might need y' as well, e.g. [{y[x] = some function, y[0] = a, y'[x] = b}, {c1, c2}]
– ivt
Sep 15, 2014 at 20:34
• Ok, I'm very spooked. How did it take you 1 second to reply to my comment?
– alexqwx
Sep 15, 2014 at 20:35
• There is definitely a way to do that, I had a hw assignment last spring where I had to do exactly this. I won't be home for a few hours, but once I get home I can send you the Syntax to calculate something like this. (If nobody else has answered the question before then)
Sep 15, 2014 at 21:25
• I think if you define the function y[_x,_c] = x + c you can call Solve[ y[0,c] == 5, c] to find the parameter c. Sep 16, 2014 at 15:37

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, 2014 at 19:03

you can enter y(0)=2 for example enter: y'+y=0,y(0)=2 i think this is solve your problem. this is for online mathmatica(www.wolframalpha.com)

• 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, 2014 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 $x^{2} - 2 = 0$

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


will return $\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