Click here to Skip to main content
15,742,377 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
lets say we have the equation

t = 122.14-0.84.*x(1)-0.42.*x(2)+0.34.*x(3)-0.09.*x(4)+363.77.*x(5); 

It have 5 variables and have some lower and upper bounds. i perform genetic algorithm and got optimum values as answers. now whatever value I got for these 5 variables. I want to use them in another equation which is-

s = - 463.21-3.05x(1) + 5.21x(2)+0.54x(3) +0.11x(4)-6541.17x(5) + 41.67x(6). 

It have 6 variables ( variable x(1) to x(5) are same ) and x(6) is unknown and have some lower and upper bounds. here, i want the output from my previous equation as an input of x(1) to x(5) variable in 2nd equation and x(6) will be treated as unknown variables having some bounds.

PS:- Since whenever I run a genetic algorithm, the output of first equation is going to change, i want your help in the code in which the output of x(1) to x(5) variable from 1st equation will automatically get assigned in my 2nd equation. now, i hope you got it. thank you for taking interest in question.

What I have tried:

function t=strength(x)
    t = 122.14-0.84.*x(1)-0.42.*x(2)+0.34.*x(3)-0.09.*x(4)+363.77.*x(5);
function [state,options,optchanged] = stop40_80(options,state,flag)
    optchanged = false;
    switch flag
        case 'init'
        case 'iter'
            % Find the best objective function, and stop if it is right range
            mask = state.Score >= 40 & state.Score <= 80;
            if any(mask)
                state.StopFlag = 'range statisfied';
                state.Score = state.Score(mask);
                state.Population = state.Population(mask,:);
                state.Best(end) = state.Score(end);
        case 'done'

this is my calling function of GA for 1st equation:-

A = []; b = []; Aeq = []; beq = []; lb = [29 160 30 0 0.040]; ub = [50 180 60 20 0.069]; nonlcon = [];
obj = @(x) (strength(x)-80).^2;
bestx = ga(obj, 5,  A, b, Aeq, beq, lb, ub, nonlcon, options);

All I want is use this data (output) from 1st equation for finding the answer of 2nd equation whose fitness function is given hereand variable x(1) to x(5) variable are same from 1st equation. just a new variable x(6) is added.

s= -463.21-3.05.*x(1)+5.21.*x(2)+0.54.*x(3)+0.11.*x(4)-6541.17.*x(5)+41.67.*x(6);
lower and upper bound of x(6)-

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900