0
$\begingroup$

I have the following coefficient finding problem:

f[x] := a * Log[b*x + c] + d

Constraints:

  • f[0] = 1
  • f[80] = 0.5

I want to find the coefficients of f that adhere to these constraints. What is the easiest way to formulate this problem in Mathematica?

Ideally, I would tell Mathematica just the constraints and which functions it is allowed to use, i.e. to not have to type out a * Log[b*x + c] + d.

$\endgroup$
6
  • 2
    $\begingroup$ You have some basic syntax problems. First, function definition should be done with an underscore (i.e. f[x_]:=...). Second, I think you meant b x (which is equivalent to b*x) and not bx. Also Log is the function, and not log, and calling functions is done with square brackets, and not round ones. $\endgroup$
    – yohbs
    Jul 9 '15 at 7:49
  • 2
    $\begingroup$ Lastly, you have 4 unknowns (a,b,c,d) and only 2 constraints. Therefore you cannot "solve" and find the unknowns, as there are infinitely many of them what will adhere to the constraints. $\endgroup$
    – yohbs
    Jul 9 '15 at 7:52
  • $\begingroup$ @bobby, somehow I'm not sure fixing OP's syntax errors for him is a good idea… $\endgroup$
    – J. M.'s torpor
    Jul 9 '15 at 8:41
  • $\begingroup$ @J. M., you have a point. I am sorry. Would rolling it back be a good idea or would it just be confusing? $\endgroup$
    – bobbym
    Jul 9 '15 at 15:57
  • $\begingroup$ @bobby, since we're here, we might as well leave it be, tho that has the effect of making yohbs's otherwise fine comment seem impertinent. $\endgroup$
    – J. M.'s torpor
    Jul 9 '15 at 16:00
3
$\begingroup$

There will be an infinite number of functions. You could approach as follows:

f[a_, b_, c_, d_, x_] := a*Log[b*x + c] + d

then

FindInstance[{f[a, b, c, d, 0] == 1,
  f[a, b, c, d, 80] == 0.5}, {a, b, c, d}, Reals]

this yields:

{{a -> 7.95441, b -> -0.098772, c -> 1297/10, d -> -(377/10)}}

or

sol = First[Quiet@Solve[{f[a, b, c, d, 0] == 1,
      f[a, b, c, d, 80] == 0.5}, {a, b, c, d}, Reals]];

Note sol is a conditional expression:

{c -> ConditionalExpression[-((
     80. 2.71828^(1/a) b)/(-1. + 2.71828^(1/a))) + (
    80. Sqrt[2.71828^(1/a) b^2])/
    Abs[-1. + 2.71828^(1/a)], (a > 0 && b < 0) || (a < 0 && b > 0)], 
 d -> ConditionalExpression[
   1. - 1. a Log[-((80. 2.71828^(1/a) b)/(-1. + 2.71828^(1/a))) + (
       80. Sqrt[2.71828^(1/a) b^2])/Abs[-1. + 2.71828^(1/a)]], (a > 
       0 && b < 0) || (a < 0 && b > 0)]}

You could find functions satisfying your constraints and conditions, e.g.

func[u_, v_] := {u, v, c, d} /. (sol /. {a -> u, b -> v})

Some functions:

func @@@ {{-1, 1}, {1, -1}, {2, -3}, {-2, 3}}

yields:

{{-1, 1, 123.32, 5.81478}, {1, -1, 203.32, -4.31478}, {2, -3, 
  1084.99, -12.9787}, {-2, 3, 844.995, 14.4787}}

Testing satisfies:

g[x_] := f[##, x] & @@ func[1, -1]

g[0] yields 1 and g[80] yields 0.5.

Or visualizing:

g[x_] := f[##, x] & @@ func[1, -1]
h[x_] := f[##, x] & @@ func[-1, 1]
i[x_] := f[##, x] & @@ func[2, -3]
j[x_] := f[##, x] & @@ func[-2, 3]
Plot[{g[x], h[x], i[x], j[x]}, {x, 0, 100}, 
 Epilog -> {Red, PointSize[0.02], Point[{{0, 1}, {80, 0.5}}]}, 
 PlotLegends -> "Expressions"]

enter image description here

$\endgroup$
1
  • $\begingroup$ Thanks a lot for the detailed explanation! $\endgroup$
    – alxppp
    Jul 9 '15 at 16:20

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.