How to optimise a definite integral?

조회 수: 31(최근 30일)
Harvey Rael
Harvey Rael 2018년 5월 27일
편집: DGM 2021년 5월 9일
In the attached image, I want to optimize the function Dt, as I know the end result of the integral. I have expressions for k1 and k0 in terms of k2 and N, and it is k2 and N that I would like to optimize. They have constraints, needing to be between certain values. I have it all setup in my code, but I am just unaware of how to tell the genetic alogrithm to optimize an integral function? Is there something I'm missing here?
EDIT: Usually, the integration is completed numerically on MATLAB, I don't actually know what the analytical result is.


sloppydisk 2018년 5월 27일
편집: sloppydisk 2018년 5월 27일
You don't need to have the analytical result, simply pass the integral as the objective function with a function handle and k2 and N as the design variables. The genetic algorithm will use the outputs of the objective function to determine its minimum. If you need help with passing the function handle please post your code.
  댓글 수: 1
Harvey Rael
Harvey Rael 2018년 5월 28일
So I have it all set up. I know that my delta t is three years, and so I have created a function y = integral - Dt, because I know my integral must = Dt, and I want to find the optimal values of the inputs when I do. below is the code, with k(1) and k(2) the variables to be optimized
function y = objective(k)
% Define constants
AU = astroConstants(2);
mu = astroConstants(4);
% Define start and finish parameters for the exponential sinusoid.
r1 = AU; % Initial radius
psi = pi/2; % Final polar angle of Mars/finish transfer
phi = pi/2;
r2 = 1.5*AU;
global k1
k1 = sqrt( ( (log(r1/r2) + sin(k(1)*(psi + 2*pi*k(2)))*tan(0)/k(1)) / (1-cos(k(1)*(psi+2*pi*k(2)))) )^2 + tan(0)^2/k(1)^2 );
k0 = r1/exp(k1*sin(phi));
R = k0*exp(k1*sin(k(1)*theta + phi));
theta_dot = sqrt((mu/(R^3))*1/((tan(0))^2 + k1*(k(1))^2*sin(k(1)*theta + phi) + 1));
z = 1/theta_dot;
y = int(z, theta, 0,(psi+2*pi*k(2))) - 94608000;
global x
I also have a constraint function for the variables :
function [c,c_eq] = myconstraints(k)
global k1 x
c = [norm(k1*(k(1)^2))-1 -norm(k1*(k(1)^2))];
c_eq = [x];
I'm hoping that I've essentially told it that y MUST =0 thus optimising for that case.
However, when I run the genetic algorithm, the error message I am currently getting is an undefined variable (theta) in the objective function.. my issue is that the integral is being integrated from theta = 0 to theta = psi + 2*pi*k(2), with k(2) being one of the variables that need to be optimized. Here is the code for the genetic algorithm. Any chance of help?
clc; clear;
ObjFcn = @objective;
nvars = 2;
LB = [0 2];
UB = [1 7];
ConsFcn = @myconstraints;
[k,fval] = ga(ObjFcn,nvars,[],[],[],[],LB,UB,ConsFcn);

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

Torsten 2018년 5월 29일
편집: Torsten 2018년 5월 29일
R = @(theta) k0*exp(k1*sin(k(1)*theta + phi));
theta_dot = @(theta) sqrt(mu./R(theta).^3./(k1*k(1)^2*sin(k(1)*theta + phi) + 1));
z = @(theta) 1./theta_dot(theta);
y = integral(z,0,(psi+2*pi*k(2))) - 94608000;
Best wishes
  댓글 수: 2
Harvey Rael
Harvey Rael 2018년 5월 29일
Hi Torsten,
I got the notification but you haven't changed anything?
Best Regards, Harvey

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

Kunwar Pal Singh
Kunwar Pal Singh 2021년 5월 8일
How to code this equation....could anyone help me ..
im getting errors in contraints
%LOGICAL Convert symbolic expression to logical array
% Y = LOGICAL(X) converts each element of the symbolic
% array X into the value true or false.
% Symbolic equations are converted to true
% only if the left and right sides are identically
% the same. Otherwise the equation is converted to
% false. Inequalities which cannot be proved will
% throw an error.
the equation is
  댓글 수: 4
Kunwar Pal Singh
Kunwar Pal Singh 2021년 5월 9일
ok thanx

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

Community Treasure Hunt

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

Start Hunting!

Translated by