Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7175879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:23:36+00:00 2026-05-28T16:23:36+00:00

Would somebody help me please in this question. I’m new in Matlab… And it’s

  • 0

Would somebody help me please in this question. I’m new in Matlab… And it’s a bit hard for me to understand how to create and use genetic algorithm in Matlab.
If anybody could help to write some very simple code for searching minimum/maximum of specified function.
I read that the gatool should be used for that… but I can’t understand the examples of Matlab help network. I’m doing the next steps:

  1. In text editor I’m typing the next:

    function y= parabola(x)
        y=x*x;
    end
    
  2. Then I’m launching the GATOOL and specifying this function like @parabola

  3. Setting the number of variables (equals 2)
  4. Initial range = [-10;10].
  5. The other parameters are set as Default

    When I press Start Button I see a result:

    Error in fitnessfcn: Input argument “x” is undefined.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T16:23:37+00:00Added an answer on May 28, 2026 at 4:23 pm

    The main problem is that you don’t understand how the toolbox works. You should refer to the documentation to get the whole idea.

    So, the fitness function should be a function handle and should return a scalar.

    fitnessfcn

    Handle to the fitness function. The fitness function should accept a
    row vector
    of length nvars and return a scalar value.

    First, your function is not well defined. If you want to define an anonymous function you should

    % A function handle to an anonymous function that returns an scalar.
    % You should change this function accordingly to your expectations.
    % Also, note that this handle could be of a function defined in a file too.
    parabola = @(x) prod(x);
    % Parameters for the GA
    optGA = gaoptimset('PlotFcns', @gaplotbestfun, 'PlotInterval', 10, 'PopInitRange', [-10 ; 10]);
    [Xga,Fga] = ga(parabola,2,optGA)
    

    The same can be achieved with the GUI of GA. In case you want to define your function in an m file you should have something like:

    parabola.m

    function [y] = parabola(x)
    % This should return a scalar
    y = prod(x);
    

    And you define the handle like fh = @parabola. And in the code above you replace parabola for the new handle, fh.

    I hope this help you get started.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can somebody help me please, I have this code : $('childcat').setHTML('Loading...'); I would like
Can somebody please help me with this difficulty I am having? I would like
Can somebody help me construct this regular expression, please... Given the following strings... "April
Could somebody please help me understand the concept of 'impersonation'? The way I understand
Somebody please help me out. This problem is killing me. I went through tones
Would somebody care to help me out with a regex to reliably recognize and
Could somebody help me.I would like to get substring of string by ant.For example
If somebody may knows a blog posting with a basic example, that would help
I would like to create a view like contacts info in new ios4. I've
To the down-voters: I understand that this was a poorly constructed question. If you'll

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.