# How to optimise a definite integral?

26 Ansichten (letzte 30 Tage)
Harvey Rael am 27 Mai 2018
Bearbeitet: DGM am 9 Mai 2021
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. ##### 0 Kommentare-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Antworten (3)

sloppydisk am 27 Mai 2018
Bearbeitet: sloppydisk am 27 Mai 2018
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 KommentarKeine anzeigenKeine ausblenden
Harvey Rael am 28 Mai 2018
Hi!
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
x=y;
end
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];
end
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);

Melden Sie sich an, um zu kommentieren.

Torsten am 29 Mai 2018
Bearbeitet: Torsten am 29 Mai 2018
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
Torsten.
##### 2 Kommentare1 älteren Kommentar anzeigen1 älteren Kommentar ausblenden
Harvey Rael am 29 Mai 2018
Hi Torsten,
I got the notification but you haven't changed anything?
Best Regards, Harvey

Melden Sie sich an, um zu kommentieren.

Kunwar Pal Singh am 8 Mai 2021
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 Kommentare3 ältere Kommentare anzeigen3 ältere Kommentare ausblenden
Kunwar Pal Singh am 9 Mai 2021
ok thanx

Melden Sie sich an, um zu kommentieren.

### Kategorien

Find more on Solver Outputs and Iterative Display in Help Center and File Exchange

R2018a

### Community Treasure Hunt

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

Start Hunting!