You have many values for both d and p? Do you want to solve it for all combinations of d and p?
Anyway, first, I would recognize that d and L are alwways combined in the same form, thus, we have d/L always. So first, substitute
X = d/L
Of course, once we know the value of X, we can always recover L, as:
L = d/X
Now your problem reduces to
p = -2*X^3 + 3*X^2
You could use a loop over all values of p, getting three roots for each value of p. Before we do even that however, do a plot.
ALWAYS PLOT EVERYTHING.
fun = @(X) -2*X.^3 + 3*X.^2;
fplot(fun,[-1,2])
yline(0);
yline(1);
See that I used the .^ operator there to avoid problems.
Because this is a cubic polynomial in X, you can think of your problem as having 3 real roots for X, whenever p is betweeen 0 and 1. For p larger than 1 or smaller than 0, the problem will have one real root and two complex roots.
For example,
polycoef = @(p) [-2 3 0 -p];
roots(polycoef(0))
ans =
0
0
1.5
roots(polycoef(-.00001))
ans =
1.5 + 0i
-1.1111e-06 + 0.0018257i
-1.1111e-06 - 0.0018257i
So if p is just slightly less than zero as I predicted, we see a real root, but then always two complex conjugate complex roots. The same thing happens at p==1, where 3 real roots turn into a real and two complex roots as we go above p=1.
For p between 0 and 1 however, three real roots for X.
roots(polycoef(0.5))
ans =
1.366
0.5
-0.36603
Again, if you then know the value of d, we can easily recover the value of L, as
L = d./X
1 Comment
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/490664-i-need-to-solve-an-equation-involving-squares-and-cubes#comment_766515
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/490664-i-need-to-solve-an-equation-involving-squares-and-cubes#comment_766515
Sign in to comment.