Problem writing fminsearch function
显示 更早的评论
I need help with code. I have identified the mathematical model as in the code below (J1,J2,J3). Each Ji includes a Pi in the range 2000-4000, but all J need to work together so all in all they work in P range 6000-12000. I needs to find the minimum value of the sum of all J. Below is my code that I try to write, but its give me error:
Error in optymalizacja2 (line 33) fun = @(P1,P2,P3) J (J1(P1)+J2(P2)+J3(P3));
Error in fminsearch (line 201) fv(:,1) = funfcn(x,varargin{:});
P1 = 2000 : 1 : 4000;
P2 = 2000 : 1 : 4000;
P3 = 2000 : 1 : 4000;
J1 = @(P1)(7.918*10.^(-20) * P1.^6) - (1.89*10.^(-15) * P1.^5) + (1.181*10.^(-11) * P1.^4) - (8.86*10.^(-8) * P1.^3) + (2.34*10.^(-4) * P1.^2) + (0.318 * P1) + 183.47 ;
J2 = @(P2)(5.41*10.^(-10) * P2.^3) - (3.51*10.^(-6) * P2.^2) + (0.071 * P2) + 3.69 ;
J3 = @(P3)(6.07*10.^(-9) * P3.^3) - (3.22*10.^(-5) * P3.^2) + (0.056 * P3)- 25.42 ;
fun = @(P1,P2,P3) J (J1(P1)+J2(P2)+J3(P3));
[x,fval] = fminsearch(fun, Rmin);
where:
R = @(P1,P2,P3)R1(P1)+R2(P2)+R3(P3);
% R is a function P - losses
Rmin = R(2000,2000,2000);
I think about use fmincon, but anyway I can't write it correctly.
3 个评论
Walter Roberson
2022-6-3
fun = @(P) J (J1(P(1))+J2(P(2))+J3(P(3)));
If you want to constrain P1,P2 and P3 as given, use fminsearchbnd:
fun = @(P) J1(P(1)) + J2(P(2)) + J3(P(3))
(I don't know what your J means in fun = @(P1,P2,P3) J (J1(P1)+J2(P2)+J3(P3));)
How R comes into play, I also could not understand.
Wiktoria Schabek
2022-6-3
采纳的回答
更多回答(1 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Performance and Memory 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!