Sei sulla pagina 1di 4

Ejercicio 1

Programa:

Función Principal.m
clc; %Limpiamos pantalla.
clear all; %Borra todas las variables del espacio de trabajo.
close all;

g=minimizar(1);

Función minimizar:

function s=minimizar(l)

%options=optimoptions('fmincon','Algorithm','sqp','maxiter',200,'Display','iter');
options=optimoptions('fmincon','Algorithm','sqp','maxiter',200);

objetivo= @(x) -x(1)*x(2);

Aeq=[sqrt(3) 1 ];
beq=(sqrt(3)/2)*l;
x0 = [rand*l ; rand*l];

lb=[0 0];
ub=[l (sqrt(3)/2)*l];

[x,fval]=fmincon(objetivo,x0,[],[],Aeq,beq,lb,ub,[],options);

s=x;

Resultados:

Local minimum found that satisfies the constraints.


Optimization completed because the objective function is non-decreasing in
feasible directions, to within the default value of the function tolerance,
and constraints are satisfied to within the default value of the constraint tolerance.

<stopping criteria details>


g=

0.2500
0.4330
Ejercicio 2:

Función minimizar.m:
clc; %Limpiamos pantalla.
clear all; %Borra todas las variables del espacio de trabajo.
close all;

global l;

l=1;

lb=0;
ub=l;
x0 =rand()*l;

A=1;
b=l;

options=optimoptions('fmincon','Algorithm','sqp','maxiter',200,'Display','iter');

[x,fval]=fmincon(@ecuacion1,x0,A,b,[],[],lb,ub,[],options);

fprintf('x = %.10f \n',x);

Función ecuacion1.m:
function f= ecuacion1(x)
global l;
f= ((l-x)/4)^2 + x^2/(4*pi);

Resultados:

Local minimum found that satisfies the constraints.

Optimization completed because the objective function is non-decreasing in

feasible directions, to within the default value of the function tolerance,

and constraints are satisfied to within the default value of the constraint tolerance.

<stopping criteria details>

x = 0.4399008404
Ejercicio 3:

Función minimizar.m:
clc; %Limpiamos pantalla.
clear all; %Borra todas las variables del espacio de trabajo.
close all;

clc; %Limpiamos pantalla.


clear all; %Borra todas las variables del espacio de trabajo.
close all;

lb=[0.003,0.003,0.003];
ub=[10,10,pi/2];
x0 =[rand()*ub(1),rand()*ub(2),rand()*ub(3)];
%options=optimoptions('fmincon','Algorithm','sqp','maxiter',200,'Display','iter');
options=optimoptions('fmincon','Algorithm','sqp','maxiter',200,'Display','iter');

[x,fval]=fmincon(@ecuacion1,x0,[],[],[],[],lb,ub,@nonlcon,options);

fprintf('x = %.10f %.10f %.10f\n',x);

Función ecuacion1:
function f= ecuacion1(x)
b = x(2)+2*x(1)/sin(x(3));
f=-1/b;

Función nonlcon.m:
function [c,ceq]= nonlcon(x)
c=[];
ceq=x(1)*x(2)+x(1)^2*cot(x(3))-100;

Resultados:

Local minimum found that satisfies the constraints.

Optimization completed because the objective function is non-decreasing in

feasible directions, to within the default value of the function tolerance,

and constraints are satisfied to within the default value of the constraint tolerance.

<stopping criteria details>

x = 7.5983567220 8.7738162116 1.0471964806


Ejercicio 4:

Función Minimizar.m:

clc; %Limpiamos pantalla.


clear all; %Borra todas las variables del espacio de trabajo.
close all;

global a;
global w;
a=50;
w=40;

lb=.000003;
ub=w;
x0 =rand();

A=1;
b=w;

options=optimoptions('fmincon','Algorithm','sqp','maxiter',200,'Display','iter');

[x,fval]=fmincon(@ecuacion1,x0,A,b,[],[],lb,ub,[],options);

fprintf('x = %.10f %.10f\n',x,fval);

Función ecuacion1:
function f= ecuacion1(x)
global a;
global w;
f= a*x+(w^3/x^2);

Resultados:

Local minimum possible. Constraints satisfied.

fmincon stopped because the size of the current step is less than

the default value of the step size tolerance and constraints are

satisfied to within the default value of the constraint tolerance.

<stopping criteria details>

x = 13.6798077492 1025.9855680060