MATLAB Answers

optimising variables that are dependent on other variables

조회 수: 1(최근 30일)
Ron Herman
Ron Herman 2020년 11월 19일
편집: Ron Herman 2020년 12월 22일
I am trying to find best coordinates and angle of inclination of line that would give me the least sum of distance between stationary curve and a line.
The curve position remains fixed but the coordinates of line can change and lines inclination can change giving me the best position of line that will give me the least sum of distance (objective function)
Can anyone suggest or hint how to use inbuilt optimization function provided in matlab to approach this problem. This is a multi variable optimization problem where we need to find best value of x,y, theta.
Diagram and constraints are given below to understand problem. The concept will help me in my research work. I have written the code as well to provide initial position of line and curve and inclination of line but I donot understand how to use inbuilt function here directly since variables of objective funtion are dependent on other variables.
Example that shows initial position and next iteration
Constraints and problem defination
code for position staionary curve and initial position of line
r = 40; % arc length
R = 55; % radius of a circle
aa = 60*pi/180; % arc angle
ap = 0*pi/180; % arc position angle
t1 = linspace(0,aa)-aa/2+ap;
[x1,y1] = pol2cart(t1,r); % arc data
%Shifting arc lower end to (60,10) (stationary arc)
% defining the line with one end at (14,15)
L = linspace(0,10); % line segment lenth max is 5 and min is 0
theta = 60*pi/180; % initial angle of inclination
% starting point at (14,15)
x=x0+ L* cos(theta);
y=y0+L * sin(theta);
% for highlighting point at distance of L/4 from both ends
ind= [25 75];
plot (x1,y1)
hold on

채택된 답변

Jon 2020년 11월 19일
If you have the optimization toolbox then you can use fmincon to solve this type of problem.
You will need to write a function, in your case may not be simple, that in the end will give you values of your objective function Z as a function of xa, ya, and theta.
  댓글 수: 13
Ron Herman
Ron Herman 2020년 12월 22일
There is another thing that was on my mind. In the current question both end points of line should lie inside the region. Here xe and ye also need to line inside the prescribed range so we used confun() function.
Before we start optimization we always give an initial value . Suppose here we give initial value to xa, ya, theta in such a way that the line (xa,ya) cordinates are inside the desired region but point (xe,ye) mentioned inside confun() are outside the region. In this situation will optimization work?????
If I rephrase the question the parameters for optimization that I use are xa,ya,theta are all within the range during the 1st initialisation or x0 , but a part of line is outside the range and thus xe,ye lie outside. This xe,ye are used in confun().
So in short do I need to set initial condition in such a way that all constrains are satisifed from start???
For example given below
The red curve is set in intial postion (xo,yo) and a particular theta that makes arc in that postion as seen in left image and we want whole arc to follow constraint of Y lb < Y < Y ub & X lb < X < X ub. (Here havent shown X constraint as it is assumed xo, x1,x2 all lie within X lb & X ub)
Here it can be seen (xo,yo) satisfy constraint but point 1 and point 2 dont satisfy at initial position.
% Constraint for end points which we write inside confun()
% For point 1
c(1) = lb(1) - x1;
c(2) = x1 - ub(1);
c(3) = lb(2) - y1;
c(4) = y1 - ub(2);
% for point 2
c(5) = lb(1) - x2;
c(6) = x2 - ub(1);
c(7) = lb(2) - y2;
c(8) = y2 - ub(2);
But when we define (xo, yo) and theta for the red arc point 1 and point 2 lie outside UB and LB . In this case will optimization work and make the arc aquire desired positon as shown in right side of image on its own.

댓글을 달려면 로그인하십시오.

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by