Hiiii having problem in coding optimazation function
Show older comments
hiii i have problem in defining objective function for optimization. my objective function is
y=sum(abs(Voc-Vbc));
where Voc is given data and Vbc is obtained by
Vbc=(((Q./C1)+(Ic*R2)).*exp(-tc./(R2.*C1)))+Vo-(Ic*(R1+R2));
in this Q tc and Ic are constant and R1 C1 R2 and Vo is obtained from
R1 = ((a(1)+a(2)*cr+a(3)*(cr^2))*exp(-a(4).*SOC))+(a(5)+a(6)*cr+a(7)*(cr^2));
R2 = ((a(8)+a(9)*cr+a(10)*(cr^2))*exp(-a(11).*SOC))+(a(12)+a(13)*cr+a(14)*(cr^2));
C1 = (-(a(15)+a(16)*cr+a(17)*(cr^2))*exp(-a(18).*SOC))+(a(19)+a(20)*cr+a(21)*(cr^2));
Vo = ((a(22)+a(23)*cr+a(24)*(cr^2))*exp(-a(25).*SOC))+(a(26)+a(27).*SOC+a(28).*(SOC.^2)+a(29).*(SOC.^3))-(a(30)*cr)+(a(31)*(cr^2));
Here SOC is an array and cr is constant a is array with (1, 31) dim . this a matrix is variable for our optimization.
in my program i want R1 C1 R2 and Vo always remain positive. how i can define it in matlab so this values always remain positive.
2 Comments
Alan Weiss
on 13 Mar 2015
Please format your question using the {} Code button so that we can read it.
Alan Weiss
MATLAB mathematical toolbox documentation
venu sangwan
on 15 Mar 2015
Answers (1)
Alan Weiss
on 16 Mar 2015
It is very hard to understand you, so my comments might be off base. I am not sure that I understand what your control variables are. Control variables are the ones that you change to try to optimize something.
Suppose that your control variables are R1, C1, R2, and V0. Then you write your objective function for the lsqnonlin function as
function y = myfun(x,Vbc)
R1 = x(1);
C1 = x(2);
R2 = x(3);
V0 = x(4)
% Now write the calculation of Voc
% End the calculation with
y = Voc - Vbc
and pass your function as
fun = @(x)myfun(x,Vbc); % gets the objective function
solution = lsqnonlin(fun,x0) % you need an initial guess x0
I hope this helps,
Alan Weiss
MATLAB mathematical toolbox documentation
1 Comment
venu sangwan
on 17 Mar 2015
Categories
Find more on Solver Outputs and Iterative Display in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!