1
$\begingroup$

Given the following equation and rule, how would I Solve the equation for tr, k and c?

eq = T == tr - E^(-k * t)*c;
rule = {t -> {0, 5, 10}, T -> {2000, 1300, 1100}};

eq /. rule results in this, which is almost what I want:

{2000, 1300, 1100} == {tr - c, tr - c/E^(5k), tr - c/E^(10k)}

I would like to get a list of equations instead like so:

{2000 == tr - c, 1300 == tr - c/E^(5k), 1100 == tr - c/E^(10k)}

which could then be used to solve the equations (using And on the list).

$\endgroup$
2
$\begingroup$

Pinguin Dirk's solution is very neat for this problem. It is possible because, as you discovered, eq /. rule generates

{2000, 1300, 1100} == {tr - c, tr - c/E^(5*k), tr - c/E^(10*k)}

But this is often not the case! It works only because Power (^) has the attribute Listable. Let's say instead of Power[E,t k] we had f[E,t k] where f is any function that is not Listable. eq /. rule yields:

{2000, 1300, 1100} == tr - c f[E, {0, -5 k, -10 k}]

If you run into this problem, a more general approach would be needed. The key to the general approach is to get your rules into this format:

rules = Thread[Thread /@ {t -> {0, 5, 10}, T -> {2000, 1300, 1100}}]

{{t -> 0, T -> 2000}, {t -> 5, T -> 1300}, {t -> 10, T -> 1100}}

Because in this format we can easily generate the required results, like this:

eq /. rules

{2000 == tr - c f[E, 0], 1300 == tr - c f[E, -5 k], 1100 == tr - c f[E, -10 k]}

$\endgroup$
4
  • $\begingroup$ The # & /@ part is redundant as a list mapped to the identity function will return the same list. eq /. rules is enough. $\endgroup$
    – Tyilo
    Oct 20 '13 at 20:57
  • $\begingroup$ @Tyilo Very observant of you, I updated the answer. $\endgroup$
    – C. E.
    Oct 20 '13 at 21:01
  • $\begingroup$ @Tyilo Although I would maintain it's not because of the reason you mention. {expr /. {a->b}, expr /. {b->c}} would not be the same as expr /. {{a->b},{b->c}} unless ReplaceAll had the seemingly undocumented property of threading over it's second argument. $\endgroup$
    – C. E.
    Oct 20 '13 at 21:07
  • $\begingroup$ oh I didn't know that what you wrote before is equal to (eq /. #)& /@ rules). I thought it was eq /. (# & /@ rules) or something else, sorry. $\endgroup$
    – Tyilo
    Oct 20 '13 at 21:25
3
$\begingroup$

Use for example:

Thread[eq/. rule]

and get:

{2000 == -c + tr, 1300 == -c E^(-5 k) + tr, 1100 == -c E^(-10 k) + tr}

$\endgroup$
2
  • $\begingroup$ @Tyilo: Thanks for the accept, but usually it pays to wait a bit... there are most certainly other people out there with other ideas, better ideas. And you don't wanna scare them away, do you? Still, I am glad you like my approach! $\endgroup$ Oct 20 '13 at 13:49
  • $\begingroup$ Fair enough, I'll wait a little longer $\endgroup$
    – Tyilo
    Oct 20 '13 at 14:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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