Message Boards Message Boards

0
|
4562 Views
|
5 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Writing a loop for multiple derivatives along roots for each derivative?

Posted 8 years ago

I am trying to write a loop that will take the first n derivatives (lets say n =3), which outputs a list that will include 1(or more) roots for each derivative.

I haven't actually set up the loop because I'm not quite sure which I want to use. (Do, For, While, maybe even Table) Here is what I have so far and I know I will need to use each of these somewhere in my loop.

 Clear[x,roots,x,n];

 f[x_] = x^8 - 3 x^5 + x - 1; (*function I am using *)

 NSolve[f'[x] == 0, x, Reals]; (* this would be for the first derivative *)

Table[D[f[x], {x, n}], {n, 1, 3}] (* I know this is helpful for showing the first n derivatives, here n = 3 *)

I'm just not sure how I should start honestly.. I've been having difficulties with loops in Mathematica. Even a simple suggestion as to which loop I should use would be great (I know you could solve this using any of the loops but I'm not that familiar with them yet).. I think N[%] would help me get those roots also.

Any help/advice is always appreci

POSTED BY: Brandon Davis
5 Replies
Posted 8 years ago
f[x_] = x^8 - 3 x^5 + x - 1
Table[NSolve[D[f[x], {x, n}] == 0, {x}], {n, 1, 3}]
POSTED BY: Okkes Dulgerci
Posted 8 years ago

Hey Okkes!

Thanks for the response. My only concern was, how will I know which roots correspond to which derivatives? This is where I thought using the "AppendTo" command would be useful. This is certainly a step in the right direction and exactly the output I was trying to produce. So thanks again!

Brandon

POSTED BY: Brandon Davis
Posted 8 years ago
f[x_] = x^8 - 3 x^5 + x - 1;
Table[{n, NSolve[D[f[x], {x, n}] == 0, {x}]}, {n, 1, 3}] // TableForm

n corresponds degree of your derivative, i.e., n=1 first derivative and 7 roots

POSTED BY: Okkes Dulgerci
Posted 8 years ago

I got it! This is what I was going for:

Clear[x, roots, x, n, d];
f[x_] = x^8 - 3 x^5 + x - 1;
n = 5;
der = D[f[x], {x, #}] & /@ Range[n];
roots = Table[NSolve[der[[#]] == 0, x, Reals] & /@ Range[n]];
Grid[{der, roots} // Transpose]

output:

{
 {1 - 15 x^4 + 8 x^7, {{x -> -0.5}, {x -> 0.518012}, {x -> 1.22064}}},
 {-60 x^3 + 56 x^6, {{x -> 0}, {x -> 0}, {x -> 0}, {x -> 1.02326}}},
 {-180 x^2 + 336 x^5, {{x -> 0}, {x -> 0}, {x -> 0.812165}}},
 {-360 x + 1680 x^4, {{x -> 0}, {x -> 0.598408}}},
 {-360 + 6720 x^3, {{x -> 0.376974}}}
}

Thanks again for your help because I was able to combine what you gave me along with some ideas I was messing around with. Great teamwork and much appreciated!

Brandon

POSTED BY: Brandon Davis
Posted 8 years ago
f[x_] = x^8 - 3 x^5 + x - 1;
Table[{n, D[f[x], {x, n}], 
   NSolve[D[f[x], {x, n}] == 0, {x}, Reals]}, {n, 1, 5}] // TableForm
POSTED BY: Okkes Dulgerci
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract