I need to solve an equation involving squares and cubes.
Mostrar comentarios más antiguos
I need to sole this equation for L, and I have a set of values for d and p.
p = -2(d/L)^3 + 3(d/L)^2
Im wondering how to put this into Matlab. Any help would be apprecitated.
1 comentario
James Tursa
el 12 de Nov. de 2019
Multiply both sides by L^3 and then you have a polynomial in L to work with.
Respuesta aceptada
Más respuestas (1)
John D'Errico
el 12 de Nov. de 2019
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
Categorías
Más información sobre Mathematics en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!