Multiparametric optimisation problem using Genetic algorithm
Show older comments
I'm currently trying to optimise a velocity demand signal with the values to be optimised being 'POINT' based on the cost function 'mycostfunction'
I've checked the value of cost changes if i differ my 'POINT' numbers but when I try to use a GA code the system crashes and when I use ga toolbox the system seems to get stuck and not get past its first iteration I am really confused can someone please help me
if true
% function cost = mycostfunction(POINT)
global POINT
global tstep
global veldem
global bspliney
global bsplinex
global response1
global controlpoints
global xycoords
global ycoords
% POINT=[48 48 48 48 48 48 48 48 48 28 28];
xycoords = [0 POINT(1); 36 POINT(2); 72 POINT(3); 108 POINT(4); 144 POINT(5); 180 POINT(6); 216 POINT(7); 252 POINT(8); 288 POINT(9); 324 POINT(10); 360 POINT(11)]; ycoords = [POINT(1); POINT(2);POINT(3);POINT(4);POINT(5); POINT(6);POINT(7);POINT(8);POINT(9);POINT(10); POINT(11)];
% close all; n = 11; % if (nargin ~= 2) order = 4; % end nplot = 100; % % if (n < order) % display([' !!! Error: Choose n >= order=',num2str(order),' !!!']); % return; % end p = xycoords;
% figure; % hold on; box on; % set(gca,'Fontsize',16);
t = linspace(0,1,nplot);
for i = 1:n % plot(p(:,1),p(:,2),'k-','LineWidth',2); % axis([0 1 0 1]); % hold on; box on; if (i >= order) T = linspace(0,1,i-order+2); y = linspace(0,1,1000); p_spl = DEBOOR(T,p,y,order); % plot(p_spl(:,1),p_spl(:,2),'b-','LineWidth',4); bspliney = p_spl(:,2); bsplinex = p_spl(:,1); controlpoints=p; end % plot(p(:,1),p(:,2),'ro','MarkerSize',10,'MarkerFaceColor','r');
end
sim 'TESTCOMPLETEwithsimulinkvariance_RRCLEANUP' A = abs((max(response1(:,6)))-(min(response1(:,6)))); B = abs((mean(response1(:,2)))-veldem); C = abs(bspliney(1)-bspliney(end)); x = [A B C]; cost = x(1) + 10000*x(2) + 10000*x(3); assignin('base','cost', cost); end
% global response1
assignin('base', 'response1', response1); end
my DEBOOR is
if true
function val = DEBOOR(T,p,y,order)
% function val = DEBOOR(T,p,y,order)
%
% INPUT: T reference points
% p control points (nx2-Matrix)
% y evaluation points (Spaltenvektor)
% order spline order
%
% OUTPUT: val Werte des B-Splines an y (mx2-Matrix)
%
% Date: 2007-11-27
% Author: Jonas Ballani
m = size(p,1);
n = length(y)
X = zeros(order,order);
Y = zeros(order,order);
a = T(1);
b = T(end);
T = [ones(1,order-1)*a,T,ones(1,order-1)*b];
for l = 1:n t0 = y(l); id = find(t0 >= T); k = id(end); if (k > m) return; end X(:,1) = p(k-order+1:k,1); Y(:,1) = p(k-order+1:k,2);
for i = 2:order
for j = i:order
num = t0-T(k-order+j);
if num == 0
weight = 0;
else
s = T(k+j-i+1)-T(k-order+j);
weight = num/s;
end
X(j,i) = (1-weight)*X(j-1,i-1) + weight*X(j,i-1);
Y(j,i) = (1-weight)*Y(j-1,i-1) + weight*Y(j,i-1);
end
end
val(l,1) = X(order,order);
val(l,2) = Y(order,order);
end
end
and what i used to run my ga was
if true
% global POINT
global tstep
global veldem
global bspliney
global bsplinex
global response1
global controlpoints
global xycoords
global ycoords
global cost
veldem = 52;
POINT = zeros(1,11);
POINT(:)=veldem;
tstep=0.001;
% gt=mycostfunction(POINT);
x0 = zeros(1,11);
x0(:) = veldem;
[x,fval,exitflag] = fmincon(@mycostfunction,x0);
dbstop if error
end
can someone please help me, I also tried running this with fmincon and although it worked, only initial values were sent back to me?
My simulink just models a four bar mechanism and returns torque which i am trying to minimise the peak to peak of
any help is greatly appreciated thank you in advance
Answers (0)
Categories
Find more on Transfer Function Models in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!