Tell me more ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

This is what I'm trying to do:

sol = DSolve[{y''[x] - 4*y'[x] + 3*y[x] == 0, y[0] == 7, y'[0] == 11}, y[x], x]
Y[x] = y[x] /. sol
z = x /. Last[NMaximize[-x^2 - 4 x + 4, x]]
Y[z]

I want to find Y[z] but I get this output instead:

(* 
{{y[x] -> E^x (5 + 2 E^(2 x))}}
{E^x (5 + 2 E^(2 x))}
-2.
Y[-2.] 
*)

What should I do?

share|improve this question
5  
I'm sorry, but I had to downvote since this was already covered in the answer to your last question. You may not be aware of it, but there's a "virtual book" provided with Mathematica that gives a very good introduction to the language and should help clear up issues like this. If you don't know where to start with the documentation, it can be very helpful! You can get to it via the book icon in the Documentation Center, or via the Help menu. – Oleksandr R. Jul 24 '12 at 18:18

closed as too localized by acl, rm -rf, Oleksandr R., Leonid Shifrin, Eli Lansey Jul 24 '12 at 18:54

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.

1 Answer

up vote 1 down vote accepted

Replace your def for Y:

Y[x_] = y[x] /. sol

So it matches any argument value instead of just x

Edit

x_ is a pattern. Read about patterns in the help! It is of utmost importance!

Also, try this:

sol = DSolve[{y''[x] - 4*y'[x] + 3*y[x] == 0, y[0] == 7, y'[0] == 11}, y[x], x]
y[x] /. sol /. Last[NMaximize[-x^2 - 4 x + 4, x]]
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.