How can I optimize coefficients of a polynomial using fmincon?

14 visualizzazioni (ultimi 30 giorni)
I have 3 equations that represents a curve in 3D space. These equations are
X(t) = at^5 + bt^4 + ct^3 + dt^2 + et + f
Y(t) = at^5 + bt^4 + ct^3 + dt^2 + et + f
Z(t) = at^5 + bt^4 + ct^3 + dt^2 + et + f
I have certain constraints for this problem. But figuring out how to write this into a function in Matlab is difficult. I don’t know what to do with the t^n. Since the parameters that are changing are the coefficients, how do I write this into Matlab? My cost function is J= sqrt( dxdt^2 + dydt^2 + dzdt^2) (Or at least, this is what I have been interpreting it as. The overall goal is to minimize the length of the cost function )
  2 Commenti
Matt J
Matt J il 28 Apr 2021
These equations are...
As you've written it, the same coefficients are used for X,Y, and Z meaning your curve has to be a straight line.
My cost function is J= sqrt( dxdt^2 + dydt^2 + dzdt^2)
This is not a scalar-valued cost function. Did you really mean,
J= sum( dxdt^2 + dydt^2 + dzdt^2)^2
Bryant Springle
Bryant Springle il 28 Apr 2021
Sorry, I should have mentioned that teh coefficients are different for each equation. I just wanted to show that each equation is modeled by a quintic polynomial. And after viewing another answer, I am now realizing that the cost function is as integral

Accedi per commentare.

Risposte (1)

Bruno Luong
Bruno Luong il 28 Apr 2021
Modificato: Bruno Luong il 28 Apr 2021
"The overall goal is to minimize the length of the cost function "
The overall length is
L = integral sqrt(dx/dt^2+dy/dt^2+dy/dt^2)(t) dt
t is then a integration variable to compute L that you want ti minimize.
You should program the code to compute L from coefficients by integrating on t, over whatever the interval that defines your curve.
  2 Commenti
Bryant Springle
Bryant Springle il 28 Apr 2021
Bruno.... I dont know why I didnt recognize that my cost function was an integral. That makes a lot of sense. I do have another question. My equality constraints and inequality constraints state that:
From the first image, it says that at those specific times, those are the x,y, and z coordinates. How would you suggest I do this in the constraint function for fmincon? Heres how I have been thinking of writing it. (I dont think this would work, so suggestions are very welcomed)
Here is an example for how I would write the initial waypoint constriant for x at t = 0.
x(t) = at^5 + bt^4 + ct^3 + dt^2 + et + f
If I put all of my coeficients into one long vector, X, I get a 18 x 1 vector, where the first 6 are the coefficients for x.
At time t = 0, f should equal 5. So I was thinking the equality constraint should be
[X(6) - 5];
Would this be a valid constraint?
Bruno Luong
Bruno Luong il 28 Apr 2021
"Would this be a valid constraint?"
Yes.
You can use Aeq/beq arguments as well since value constraints us a linear constraint wrt coefficients.

Accedi per commentare.

Prodotti


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by