''Conversion to function_handle from double is not possible.''

조회 수: 1 (최근 30일)
Dario Miric
Dario Miric 2022년 1월 25일
댓글: Torsten 2022년 1월 26일
I get this error when I run my code. I was looking up what this error means, but I can't figure it out in context of my code.. This is main code.
clc
clear all
global x1e x2e x3e x1r x2r x3r alfa12 alfa13 alfa23
%LLE podatci - ekstrakcija aromata smjesom TTEG i vode - 6 komponenata (heptan) na 60°C
%eksperimentalni podatci - ekstrakt
x1e = [0.0140 0.0175 0.0163 0.0188 0.0181 0.0227 0.0228 0.0214 0.0191 0.0208];
x2e = [0.0729 0.0696 0.106 0.1041 0.1107 0.0931 0.0732 0.0739 0.113 0.069];
x3e = 1 - x1e - x2e;
%eksperimentalni podatci - rafinat
x1r = [0.689 0.6289 0.485 0.4727 0.4332 0.6831 0.6967 0.6553 0.4507 0.6139];
x2r = [0.275 0.2855 0.4418 0.3501 0.4056 0.313 0.2716 0.271 0.4436 0.253];
x3r = 1 - x1r - x2r;
%Optimizacija NRTL parametara - Metoda Sorensena i Arlta
%1. stupanj optimizacije - opis fazne ravnoteze - geneticki algoritam
%parametri neslucajnosti
alfa12 = 0.3;
alfa13 = 0.3;
alfa23 = 0.2;
rng default
%poziv funkcije cilja
OF_A = @OF_2_6H_60C;
%definiranje strukture problema
problem.fitnessfcn = OF_A;
problem.nvars = 6;
problem.options = optimoptions('ga');
[x,fval] = ga(problem)
This is function I called in main code.
function [OF2] = OF_2_6H_60C(tau12,tau13,tau21,tau23,tau31,tau32)
global x1e x2e x3e x1r x2r x3r alfa12 alfa13 alfa23
syms tau12 tau13 tau21 tau23 tau31 tau32
G12 = exp(-alfa12*tau12);
G13 = exp(-alfa13*tau13);
G21 = exp(-alfa12*tau21);
G23 = exp(-alfa23*tau23);
G31 = exp(-alfa13*tau31);
G32 = exp(-alfa23*tau32);
A1e = (x2e.*tau21*G21 + x3e.*tau31*G31)./(x1e + x2e.*G21 + x3e.*G31) + (((x1e./(x1e + x2e.*G21 + x3e.*G31)).*(-(x2e.*tau21*G21 + x3e.*tau31*G31)./(x1e + x2e.*G21 + x3e.*G31))) + ((x2e.*G12)./(x1e.*G12 + x2e + x3e.*G32)).*(tau21 - (x1e.*tau12*G12 + x3e.*tau32*G32)./(x1e.*G12 + x2e + x3e.*G32))) + ((x3e.*G13./(x1e.*G13 + x2e.*G23 + x3e)).*(tau31 - (x1e.*tau13*G13 + x2e.*tau23*G23)./(x1e.*G13 + x2e.*G23 + x3e)));
gamma1e = exp(A1e);
A2e = (x1e.*tau12*G12 + x3e.*tau32*G32)./(x1e.*G12 + x2e + x3e.*G32) + ((x1e.*G21./(x1e + x2e.*G21 + x3e.*G31)).*(tau12 - (x2e.*tau21*G21 + x3e.*tau31*G31)./(x1e + x2e.*G21 + x3e.*G31))) + ((x2e./(x1e.*G12 + x2e + x3e.*G32)).*(-(x1e.*tau12*G12 + x3e.*tau32*G32)./(x1e.*G12 + x2e + x3e.*G32))) + ((x3e.*G23./(x1e.*G13 + x2e.*G23 + x3e)).*(tau32 - (x1e.*tau13*G13 + x2e.*tau23*G23)./(x1e.*G13 + x2e.*G23 + x3e)));
gamma2e = exp(A2e);
A3e = (x1e.*tau13*G13 + x2e.*tau23*G23)./(x1e.*G13 + x2e.*G23 + x3e) + ((x1e.*G21./(x1e + x2e.*G21 + x3e.*G31)).*(tau13 - (x2e.*tau21*G21 + x3e.*tau31*G31)./(x1e + x2e.*G21 + x3e.*G31))) + ((x2e.*G32./(x1e.*G12 + x2e + x3e.*G32)).*(tau23 - (x1e.*tau12*G12)./(x1e.*G12 + x2e + x3e.*G32))) + ((x3e./(x1e.*G13 + x2e.*G23 + x3e)).*(-(x1e.*tau13*G13 + x2e.*tau23*G23)./(x1e.*G13 + x2e.*G23 + x3e)));
gamma3e = exp(A3e);
A1r = (x2r.*tau21*G21 + x3r.*tau31*G31)./(x1r + x2r.*G21 + x3r.*G31) + ((x1r./(x1r + x2r.*G21 + x3r.*G31)).*(-(x2r.*tau21*G21 + x3e.*tau31*G31)./(x1r + x2r.*G21 + x3r.*G31))) + ((x2r.*G12)./(x1r.*G12 + x2r + x3e.*G32)).*(tau21 - ((x1r.*tau12*G12 + x3r.*tau32*G32)./(x1r.*G12 + x2r + x3r.*G32))) + ((x3r.*G13./(x1r.*G13 + x3r)).*(tau31 - (x1r.*tau13*G13 + x2r.*tau23*G23)./(x1r.*G13 + x2r.*G23 + x3r)));
gamma1r = exp(A1r);
A2r = (x1r.*tau12*G12 + x3r.*tau32*G32)./(x1r.*G12 + x2r + x3r.*G32) + ((x1r.*G21./(x1r + x2r.*G21 + x3r.*G32)).*(tau12 - (x2r.*tau21.*G21 + x3r.*tau31*G31)./(x1r + x2r.*G21 + x3r.*G31))) + ((x2r./(x1r.*G12 + x2r + x3r.*G32)).*(-(x1r.*tau12*G12 + x3r.*tau32*G32)./(x1r.*G12 + x2r + x3r.*G32))) + ((x3r.*G23./(x1r.*G13 + x2r.*G23 + x3r)).*(tau32 - (x1r.*tau13*G13 + x2r.*tau23*G23 + x3r)));
gamma2r = exp(A2r);
A3r = (x1r.*tau13*G13 + x2r.*tau23*G23)./(x1r.*G13 + x2r.*G23 + x3r) + ((x1r.*G31./(x1r + x2r.*G21 + x3r.*G31)).*(tau13 - (x2r.*tau21*G21 + x3r.*tau31*G31)./(x1r + x2r.*G21 + x3r.*G31))) + ((x2r.*G32./(x1r.*G12 + x2r + x3r.*G32)).*(tau23 - (x1r.*tau12*G12)./(x1r.*G12 + x2r + x3r.*G32))) + ((x3r./(x1r.*G13 + x2r.*G23 + x3r)).*(-(x1r.*tau13*G13 + x2r.*tau23*G23)./(x1r.*G13 + x2r.*G23 + x3r)));
gamma3r = exp(A3r);
for i = 1:10
A(i)=((x1e(i)*gamma1e(i) - x1r(i)*gamma1r(i))/(x1e(i)*gamma1e(i) + x1r(i)*gamma1r(i))^2) + ((x2e(i)*gamma2e(i) - x2r(i)*gamma2r(i))/(x2e(i)*gamma2e(i) + x2r(i)*gamma2r(i))^2) + ((x3e(i)*gamma3e(i) - x3r(i)*gamma3r(i))/(x3e(i)*gamma3e(i) + x3r(i).*gamma3r(i))^2);
end
F2 = sum(A,'all');
OF2 = matlabFunction(F2)
end
  댓글 수: 5
Dario Miric
Dario Miric 2022년 1월 25일
편집: Dario Miric 2022년 1월 25일
Hmm, thanks. I thought I needed to define parameters as symbolic variables because matlab wouldn't know what these are without defining them first in some way. What you said has sense in context of have ga algorithm works in matlab. Can I leave tau's as parameters because it is a lot of work to change every parameter to x?
Torsten
Torsten 2022년 1월 26일
In function OF_2_6H_60C, you can work with the name tau for the variables.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Surrogate Optimization에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by