Write a MATLAB script file that will find the values of X and Y required to minimize the function f(x,y) = 30x + 60y + 40pi*y subject the constraining function g(x,y) = 2xy + (pi*y^2)/2 - 1600 using the method of the Lagrange Optimization Technique.
PSO IS ONE OF THE LAGRANGE OPTIMIZATION TECHNIQUE : SO;
MAT LAB CODE FOR THIS:
FUNCTION INPUT CODE:
function z=function_please(x,y)
z= 30x + 60y + 40pi*y;
end
CONSTRAINS INPUT CODE:
function ret=constraints(x,y)
ret = 30x + 60y + 40pi*y;
%Give constrains
c=[];
c(1) = 2xy + (pi*y^2)/2 - 1600;
s=zeros(1,length(c));
for i=1:length(c)
if c(i)>=0
s(1,i)=0;
else
s(1,i)=1;
end
end
excess = inf;
ret=ret+excess*sum(s);
ORGINAL CODE:
clc;
clear;
close all;
%% Problem Definition
fun = @(x,y) function_please (x,y);
nVar =2;
VarSize = [1 nVar];
VarMin = -10;
VarMax = 10;
%% Parameters of PSO
MaxIt = 100; % Maximum Number of Iterations
nPop = 100; % Population or Swarm size
w = 1;
wdamp = 0.98;
c1 = 2;
c2 = 2;
%% Initialization
% The Particle Template
empty_particle.Position = [];
empty_particle.Velocity = [];
empty_particle.funval = [];
empty_particle.Best.Position = [];
empty_particle.Best.funval = [];
%Create Population Array
particle = repmat(empty_particle, nPop, 1);
%Intialize Global Best
GlobalBest.funval = inf;
%Initialize Population Members
for i=1:nPop
%Generate Random Position
particle(i).Position = unifrnd(VarMin, VarMax,
VarSize);
%Intialize Velocity
particle(i).Velocity = zeros(VarSize);
% Evaluation
%particle(i).funval = fun(
particle(i).Position);
particle(i).funval =
constraints(particle(i).Position);
%Update the Personal Best
particle(i).Best.Position =
particle(i).Position;
particle(i).Best.funval =
particle(i).funval;
%Update Global Best
if
particle(i).Best.funval < GlobalBest.funval
GlobalBest = particle(i).Best;
end
end
% Array to Hold Best Cost value on Each Iteration
BestCosts = zeros(MaxIt, 1);
%% Main Loop of PSo
for it=1:MaxIt
for i=1:nPop
%Update Velocity
particle(i).Velocity = (w*particle(i).Velocity)...
+(c1*rand(VarSize).*(particle(i).Best.Position -
particle(i).Position))...
+(c2*rand(VarSize).*(GlobalBest.Position -
particle(i).Position));
%Update Position
particle(i).Position = particle(i).Position +
particle(i).Velocity;
%particle
particle(i).Position = max(particle(i).Position, VarMin);
particle(i).Position = min(particle(i).Position, VarMax);
%Evaluation
particle(i).funval = constraints(particle(i).Position);
%Update Personal Best
if particle(i).funval < particle(i).Best.funval;
particle(i).Best.Position = particle(i).Position;
particle(i).Best.funval = particle(i).funval;
%Update Global Best
if particle(i).Best.funval < GlobalBest.funval
GlobalBest = particle(i).Best;
s=particle(i).Best.Position;
end
end
end
%Store The Best Cost
Value
BestCosts(it) =
GlobalBest.funval;
%Display Iterantion
Information
disp(['Iteration '
num2str(it) ':Best Cost = ' num2str(BestCosts(it))]);
% Damping Intertia
Coeffient
w = w * wdamp;
end
disp(GlobalBest);
figure;
semilogy(BestCosts, 'LineWidth', 2);
xlabel('Iteration');
ylabel('Best Cost');
Write a MATLAB script file that will find the values of X and Y required to...
Write a MATLAB script to plot the function of f(x) given by: Write a MATLAB script to plot the function of f(x) given by: f(x) = integral x^2 - pi^2/4 x > pi/2 8 * cos x -pi/2 lessthanorequalto x lessthanorequalto pi/2 pi^2/4 - x^2 x < -pi/2
Write a Matlab script to complete the following: 1. Write a script file that allows a user to: a. Plot a function from a list b. Change the function coefficients c. Choose function range and number of points d. Replot a new function on the same graph keeping the original function e. Replot a new function on the same graph overwriting the original function f. Save the graph (as a png file) Functions to choose from: y A sin(Bx +...
Consider the function f(x) = x3 – 2x2 + x Write the MATLAB code in the format of "script file" using "Regula Falsi Method" with the estimated relative error of 0.000001 and upload the script file. Direction: 1) Please submit"script file", NOT "function file". If you submit a function file, I will assign ZERO score. 2) You can find some matlab code for the Regula Falsi Method on a web or some books. You can use any code you can...
3 Find the minimum and maximum values of the function f(x, y)= x +y subject to the constraint x + y 1250. Use the Lagrange Equations. (Use symbolic notation and fractions where needed.) maximum value of the function minimum value of the function cBook Hint 3 Find the minimum and maximum values of the function f(x, y)= x +y subject to the constraint x + y 1250. Use the Lagrange Equations. (Use symbolic notation and fractions where needed.) maximum value...
DO THIS IN MATLAB PLEASE DO THIS IN MATLAB Create a script file that performs the following calculations. Your script will use the functions you create. Label all graphs appropriately. For this project, do not have your homemade functions fprintf anything, instead have all your fprintf commands within your script. Attach your published script file along with .m files for your functions. Exercise 1. A fundamental iterative method for finding the roots of equations of one-variable is known as Newton's...
Problem 1: Use MATLAB to create a script file and publish a pdf file for the problem: For x equal to 1.5 at intervals of 0.05 y = 6.25 +1.8 Create a rectangular plot of x&y. Submit the published pdf file. Problem 2: Use MATLAB to create a script file and publish a pdf file for the problem: Create a bar chart for Grade А B Students 48 37 29 2 6 D F Submit the published pdf file. Problem...
3. Find the minimum and maximum values of the function f (x, y) = x2 + y subject to the constraint x y = 162. Use the Lagrange Equations. (Use symbolic notation and fractions where needed.) maximum value of the function| minimum value of the function 3. Find the minimum and maximum values of the function f (x, y) = x2 + y subject to the constraint x y = 162. Use the Lagrange Equations. (Use symbolic notation and fractions...
Develop a MATLAB script (M-File) to plot the function: y(x)-2l0g(10x) for the range of 0 sxs 10.
In 11,) Find = classify any relative extrema Of f(x,y)=2x² 4 xy + 2 / 4 g 12.) Use the method of Lagrange multipliers to minimize f(x, y) = x² + y² subject to the constraint equation - 3x + g = 30 (You do NOT have to verify that it is a minimum.
Matlab please Using the X and Y values below, write a MATLAB function SECOND_DERIV in MATLAB. The output of the function should be the approximate value for the second derivative of the data at x, the input variable of the function Use the forward difference method and interpolate to get your final answer. X=[1,1.2,1.44,1.73,2.07,2.49,2.99,3.58,4.3,5.16,6. 19,7.43,8.92, 10.7,12.84,15.41,18.49]; Y=[18.89,19.25,19.83,20.71,21.96,23.6,25.56,27.52,28.67,27.2,19.38,-2.05,-50.9,-152.82,-354.73,-741.48,-1465.11];