Optimization problem with cost function containing definite integral with one endpoint being part of the solution vector

2 visualizaciones (últimos 30 días)
I am attempting to fit a curve between two points. My starting point was naturally this code here: https://www.mathworks.com/matlabcentral/answers/159931-given-two-points-fit-a-curve#answer_156452
However, the curve needs to be of a prescribed length (say 12 units). The endpoint y-coordinate is predefined, but the endpoint x-coordinate is part of the solution vector. The only thing I could think of to try to do this was to use the arc length formula
in my cost function, where a = 0 and b is part of the solution vector. This also means that the interval over which fseminf tests its solution (at least, I assume that's what w is) is part of the solution vector.
Unfortunately, when I attempted this, I received the error: "Failure in initial objective function evaluation. FSEMINF cannot continue."
My code is laid out below:
f=@poly;
df=@dpoly;
y0 = 0;
yn = -3;
x0 = 0;
p0 = [1, 12];
costfun = @(p,S) cf(p,S,x0,y0,yn,f);
func = @(p,S) myinfcon(p,S,x0,y0,yn,df);
[x, fval] = fseminf(costfun, p0, 1, func)
Not enough input arguments.

Error in solution>@(p,S)cf(p,S,x0,y0,yn,f) (line 11)
costfun = @(p,S) cf(p,S,x0,y0,yn,f);

Error in fseminf (line 386)
initVals.f = feval(funfcn{3},x,varargin{:});

Caused by:
Failure in initial objective function evaluation. FSEMINF cannot continue.
function [c,ceq,K1,S] = myinfcon(p,S,x0,y0,yn,df)
c=[]; ceq=[];
if isnan(S)
S=[(p(2)-x0)/10, 0];
end
w=x0:S(1):p(2);
K1=sign(y0-yn)*df(p,w);
end
function out = poly(p, x)
out = p(1)*x.^2;
end
function out = dpoly(p, x)
out = 2*p(1)*x;
end
function c = cf(p, x, x0, y0, yn, f)
syms intx
expr = sqrt(1 + (2*p(1)*intx)^2); %Arc length formula, 2*p(1)*intx is f'(x)
c1 = (int(expr, [x0, p(2)]) - 12)^2;
c2 = (f(p,x0)-y0)^2 + (f(p,p(2))-yn)^2;
c = c1+c2;
end
Is there any way to salvage this, or another way to approach my problem? The issue appears to be occuring in my cost function, so the fact that the stepsize S is variable depending on the current solution vector doesn't appear to be the problem.
  2 comentarios
John D'Errico
John D'Errico el 23 de Mzo. de 2023
There are infinitely many curves passing between two points, with some prescribed arc length. Or ZERO curves, if the arc length is too small.
But fitting a curve makes no sense, because you could arbitrarily choose any of the possible candidate curves. Would you be happy with ANY such curve, as long as it satisfies the given arc length?
Or would you want some how the entire family of curves that pass through those two points, in some way parameterized? This would be a much more difficult problem of course to characterize a complete set of curves with a given arc length. But you could arguably define the curves as a set of parametrix cubics, say x(t) and y(t), that pass through the given points. But even with a fairly simple form like that, there will be infinitely many such cubics with a given arc length, and no simple way to describe the entire set for any specific arc length.
Do you have some sort of goal for the overall shape of the curve?
Carleen McKenna
Carleen McKenna el 24 de Mzo. de 2023
It needs to basically be parabolic and have a derivative of zero at the origin. As you can see, my functions contain a simple quadratic expression. It's meant to represent the bending of a wing with a set tip deflection distance. In this case, the deflection distance is the y-coordinate of the point which the parabola should pass through.

Iniciar sesión para comentar.

Respuesta aceptada

Matt J
Matt J el 23 de Mzo. de 2023
You've written your functions in terms of 2 arguments (p,S), whereas fseminf expects all the unknowns to be part of one argument, e.g.,
costfun = @(pS) cf(pS(1),pS(2),x0,y0,yn,f);
  3 comentarios
Torsten
Torsten el 23 de Mzo. de 2023
Editada: Torsten el 23 de Mzo. de 2023
syms intx
expr = sqrt(1 + (2*p(1)*intx)^2); %Arc length formula, 2*p(1)*intx is f'(x)
You have many problems here. "intx" is a symbolic scalar. So "expr" is a symbolic scalar, thus in principle a number like e.g. 4. I wonder what the intention then is with the following command:
int(expr, [x0, p(2)])
You want to integrate a constant from x0 to p(2) ? Simple: The result is expr*(p(2)-x0). But is this really what you intend ?
Furthermore, fseminf does not work with symbolic variables, only numerical. So whatever you try here, you will have to use "integral" instead of "int".
Could you perhaps explain in your own words what the intention of your code is ?
Carleen McKenna
Carleen McKenna el 23 de Mzo. de 2023
Huh? I'm just trying to integrate an expression, the arc length formula, with respect to x. intx was just used as a stand-in because originally there was already an input variable defined as "x".
The point of that code is to find the arc length of the parabola generated where p(1) is the coefficient of x^2 and p(2) is the x-coordinate of a point on the parabola such that the arc length of the parabola between x = [0, p(2)] is as close to 12 units as possible.

Iniciar sesión para comentar.

Más respuestas (0)

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by