I am new to this forum and Mathematica and could really use your help .
My ultimate goal is to get a simple 4th degree polynomial equation that I can code into a program. Here is the method I’m using to acheive this goal:
I have an equation
y = x + x^2 + x^3 + x^4
that I need to solve for multiple positive values of y. For example, I used
Solve[x + x^2 + x^3 + x^4 == .55]
which gives me x=0.358668 [I’m only interested in the positive value of x]. For my analysis, y can range between 0 and 100. I started to manually change it’s value .05 at a time, plugging it into Solve[] and writing down each of the calculated values. This is obviously very manually intensive.
Once I got enough values to see if it would work [48 in this case], I used regression analysis in Excel to create an equation
that I can code in my program. I need a more efficient way to do this and thought that I could do it all in Mathematica…
Something like:
for y=0 to 100, step .05, solve for x where y = x + x^2 + x^3 + x^4 [this would produce a dataset of y and x values where the y values go from 0, 0.05, 0.10, 0.15, … 99.95, 100.0 and a corresponding x value is generated from solving the equation]
using the output dataset from above and regression analysis, create a 4th degree polynomial equation like k above.
is this doable in Mathematica?
Any help/suggestions would be greatly appreciated.
If you will not follow the tutorial, other members of community may not be able to test your code. To edit your post click Edit in the lower right corner of your post.
Then take that bit by bit, and usually from the “inside out” by understanding how each part of each argument to each function works first. Look the bits up in the help system and try to figure out what the strategy was to do this. Why was Table used? Why was there a Select inside that? Can you identify the second argument given to Select and how does that puzzling notation work? You can also try running simplified versions of this, discovering what happens when you don’t include some parts. what do you get if you don’t use the Map[Flatten,…], but just use the … part? All this should help you greatly in the future.
Neil, if you are looking to use the inverse of this function (x+x^2+x^3+x^4) in your program, it might be better to implement a simple numerical solver (Newton’s method) tailored to this specific equation rather than approximating it with another fourth order polynomial (the approximation is not going to be good---I just checked). I found this way to be very efficient for evaluating the roots of polynomials in numerical codes. It is also simple to implement.
Szabolcs, you are correct, the approximation is not good [I thought I was being clever but not-so-much]. I do not know how to do what you are suggesting. Could you please share what you’ve found?
This may be what you are looking for, it solves all 10,000 equations, stores them in a list and uses Fit on the data. Seperate the ans part so you can try different modles once the data has been calculated.
Clear[x]; list = {}; list = Reap[Do[a = Solve[x + x^2 + x^3 + x^4 == n && x > 0, Reals];
a = x /. a; Sow[{n, a}], {n, 0.1, 100, .01}]]; list =
Partition[Flatten[list[[2]]], 2]; ans = TraditionalForm[Fit[list, {1, x, x^2, x^3, x^4}, x]]
-9.78157*10^-8 x^4+0.0000237103 x^3-0.00209162 x^2+0.0917249 x+0.606326