Question

Please answer this question using matlab MATLAB Question You are given the function

Please answer this question using matlab

MATLAB Question

You are given the function

0 0
Answer #1

%MATLAB PROGRAM MINIMISING f(x1,x2) USING GENETIC ALGORITHM WITHOUT
%CONSTRAINTS

clc
clear

f = @(x) 2.*x(1).^2 - 2.*x(1).*x(2) + 2.*x(2).^2 - 6.*x(1) + 6;
xmin = -4; xmax = 4;
num_vars = 2; % number of variables = 2 (x1 and x2)

%applying ga
[X,fmin] = ga(f,num_vars,[],[],[],[],xmin,xmax,[],[])

%solutions
x1 = X(1)
x2 = X(2)
minimum_f_value = fmin


x1 = 2.0000 x2 = 1.0000 minimum f value = 2.6944e-09

%MATLAB PROGRAM MINIMISING f(x1,x2) USING GENETIC ALGORITHM A CONSTRAINT

function [c,ceq ] = constraint(x)
ceq = x(1)+x(2)-2; %equality constraint x1+x2 = 2
c = []; %inequality constraint
end

-------------------------

clc
clear

f = @(x) 2.*x(1).^2 - 2.*x(1).*x(2) + 2.*x(2).^2 - 6.*x(1) + 6;
xmin = -4; xmax = 4;
num_vars = 2;

%applying ga
[X,fmin] = ga(f,num_vars,[],[],[],[],xmin,xmax,@constraint,[]);

%solutions
x1 = X(1)
x2 = X(2)
minimum_f_value = fmin

x1 - 1.5000 x2 0.5000 minimum f value 0.5000

%MATLAB PROGRAM PLOTTING CONTOURS OF f(x1,x2)

close all
clear
clc

f = @(x1,x2) 2.*x1.^2 - 2.*x1.*x2 + 2.*x2.^2 - 6.*x1 + 6;
x1 = linspace(-4,4);
x2 = linspace(-4,4);
[X1,X2] = meshgrid(x1,x2);
F = f(X1,X2);
num_contours = 100;
figure
[C,h]=contour(X1,X2,F,num_contours)
title('contour plot of f(x1,x2) = 2*x1^2 - 2*x1*x2 + 2*x2^2 - 6*x1 + 6')
xlabel('x1'),ylabel('x2')
%clabel(C,h) % show contour levels (values)

contour plot of f(x1 x2)-2X12-2X1%2 + 2X22-6X1 + 6 4 2 -2 -4 -3 -2 4 x1

contour plot of f(x1x2)-2x12-2X1%2 + 2%22-6X1+ 6 124765 12.4711 229 8.734 7.4865 6 3.744 2.4964 1 2489 4.9915 6.239 4.9915

COMMENT DOWN FOR ANY QUERY RELATED TO THIS ANSWER,

IF YOU'RE SATISFIED, GIVE A THUMBS UP

Know the answer?
Add Answer to:
Please answer this question using matlab MATLAB Question You are given the function
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please answer this question using Matlab: Write a matlab function to generate and plot a sine...

    Please answer this question using Matlab: Write a matlab function to generate and plot a sine wave at a specified frequency having at least 10 cycles, for this case the amplitude will represent voltage. Your sine wave should have a positive going zero crossing at T=0. Make sure your plot has at least 25 samples per cycle. Make sure the plot is with respect to time. Your function needs to return your generated samples and time vector. The frequency will...

  • MatLab question, please answer in matlab. %{ Write a function that prints the area and circumference...

    MatLab question, please answer in matlab. %{ Write a function that prints the area and circumference of a circle for a given radius. Only the radius is passed to the function. The function does not return any values. The area is given by pi*r^2 and the circumference is 2*pi*r. The function is called areaCircum. Example: areaCircum(input value) %} % Place your function call here

  • MATLAB QUESTION Find the answer for the given application of first-order differential equation using MATLAB. NOTE:...

    MATLAB QUESTION Find the answer for the given application of first-order differential equation using MATLAB. NOTE: Screenshot the MATLAB ENVIRONMENT together with the CODES and FINAL ANSWERS. PLEASE SOLVE USING MATLAB CODE! PLEASE SOLVE USING MATLAB CODE! PLEASE SOLVE USING MATLAB CODE! A racquetball is hit straight upward with an initial velocity of 2m/s. The mass of a racquetball is approximately 0.0427 kg. Air resistance acts on the ball with a force numerically equal to 0.50, where v represents the...

  • MATLAB QUESTION Find the answer for the given application of higher order differential equation using MATLAB....

    MATLAB QUESTION Find the answer for the given application of higher order differential equation using MATLAB. NOTE: Screenshot the MATLAB ENVIRONMENT together with the CODES and FINAL ANSWERS. PLEASE SOLVE USING MATLAB CODE! PLEASE SOLVE USING MATLAB CODE! PLEASE SOLVE USING MATLAB CODE! Assume an object weighing 2 lb stretches a spring 6 in. Find the equation of motion if the spring is released from the equilibrium position with an upward velocity of 16 ft/sec. What is the period of...

  • please answer the question using matlab Problem 3. (you need to include your matLab commands to...

    please answer the question using matlab Problem 3. (you need to include your matLab commands to receive any point, and be sure your answer is valid to at least two decimal places). Use the zooming technique to find solutions of the equation 8- 3sin(x)

  • please answer this in matlab so it can match the function. thank you - L -...

    please answer this in matlab so it can match the function. thank you - L - - - - - -2 t (s) Entire an equivalent function for the plot shown here using the step function, u(t)

  • Please answer question on MATLAB showing work and the script. Thank you. Create a function M-ile...

    Please answer question on MATLAB showing work and the script. Thank you. Create a function M-ile that will implement a for loop to perform the tollowing tasks for a random input array, tt x. Count how many elements are greater than an arbitrary integer and display these values as well as the count using fprintf. loop to perform the following tasks Create a function M-ile that will implement a for l for a random input array, x. Calculate the arithmentic...

  • Matlab please Using the X and Y values below, write a MATLAB function SECOND_DERIV in MATLAB....

    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];

  • Using Matlab can you please write the code for question 5. Display the zl and 22...

    Using Matlab can you please write the code for question 5. Display the zl and 22 results using the table function. 5. Create an anonymous function (name it perm) to determine how many arrangements of a subgroup n are possible from a total group size of m when the order is important (permutations). Test the function with m= 10 and n 3 . Use an fprintf statement to display the answer

  • MATLAB QUESTION Find the general solution of the given application of differential equation using MATLAB. NOTE:...

    MATLAB QUESTION Find the general solution of the given application of differential equation using MATLAB. NOTE: Screenshot the MATLAB ENVIRONMENT together with the CODES and FINAL ANSWERS. PLEASE SOLVE USING MATLAB CODE! PLEASE SOLVE USING MATLAB CODE! PLEASE SOLVE USING MATLAB CODE! A circuit has in series an electromotive force given by E=50sin(20t) volts, R=5 ohms, I= 0.4 Henrys. If the initial currents is 0, find the current at time t> 0. Guaranteed upvote once done perfectly.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT