0
$\begingroup$

Here is my function:

f[x_] := x^2 + k*x

I can plot this function to see its behavior but I certainly cannot obtain an answer by this visualization

Plot3D[f[x], {x, 0, 10}, {k, 0, 10}]

I will eventually create a loop for the question at hand, but I want to know what that k value would be in advance before I begin creating my loop that'll find k for me. I guess you could say I'm trying to work backwards.

I tried creating a table (by hand) starting at x = 0, then finding what that equation for f(x) is, then using arbitrary k values to try and come up with something. I'm not sure how I would go about finding a slope from that though.

UPDATE

slope[m_] := (
f[x_] := x^2 + k*x;
g[x_] = D[f[x], x] /. x -> Sqrt[k]; 
k = 1;
While[g[x] < m, k; k++];
k)
slope[20]
$\endgroup$
2
  • $\begingroup$ Well, you can find the slope with f'[Sqrt[k]] and solve for where they're equal with Solve[]. $\endgroup$
    – Michael E2
    Oct 16, 2016 at 23:38
  • $\begingroup$ That's a good point. Thanks @MichaelE2 $\endgroup$
    – Brandon
    Oct 16, 2016 at 23:42

2 Answers 2

3
$\begingroup$

Why not solve it analytically, using the fact that the slope is the derivative?

   f[x_] = x^2 + k*x;
   g[k_] = D[f[x], x] /. x -> Sqrt[k];
   Solve[g[k] == 20, k]

Then round k to the nearest integer value.

$\endgroup$
2
  • $\begingroup$ That's quite handy. Thank you Lauren! $\endgroup$
    – Brandon
    Oct 16, 2016 at 23:42
  • $\begingroup$ That was kind of silly on my part not to realize that. $\endgroup$
    – Brandon
    Oct 16, 2016 at 23:44
0
$\begingroup$
f[x_] := x^2 + k*x
k = 0;
While[(D[f[x], x] /. x -> Sqrt[k]) < 20, k++];
k

13

$\endgroup$
1
  • $\begingroup$ very nice, I posted the code I came up with. Thanks! $\endgroup$
    – Brandon
    Oct 18, 2016 at 20:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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