Hi. I have a problem with the definition of a script. I have 2 functions of 3 variables. I need ( if it exists maybe with fmincon) a way to find the optimum valors for the three variables in order to maximize simultaniously the two equations. Thanks a lot

댓글 수: 2

Stephan
Stephan 2018년 11월 27일
If you want more than blind suggestions, we would need to see your code.
Marcellino D'Avino
Marcellino D'Avino 2018년 11월 27일
i can't give you exactly the code because equations are genereted form a fitting. But i can summarize the prblem. I have a mixture of 3 component and their compositions are the three variables x1, x2 and x3.
So i have 2 equations for example each of those has this structure:
y=B1x1+B2x2+B3x3+B4x1*x2+B5*x1*x3+B6*x2*x3
B1,B2... are the coefficeints of my function determinated by fitting sperimental data on y and x1,x2 and x3.
So my question is: once i get this 2 equations there is a way to maximize both simultaniusly to find the optimum valors of x1, x2 and x3?

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

 채택된 답변

Star Strider
Star Strider 2018년 11월 27일

0 개 추천

One approach:
f = @(x) norm([x(1).^2 + 2*x(2) + x(3); exp(x(1)).*sin(x(2)) + cos(x(3))]);
[X, fval] = fminunc(@(x)-f(x), rand(3,1));
Here ‘f’ has 2 equations in 3 unknowns. Use your own equations, and your own constraints with fmincon.

댓글 수: 10

Marcellino D'Avino
Marcellino D'Avino 2018년 11월 27일
i don't understand. I can use with fminunc the same option of fmincon?
Star Strider
Star Strider 2018년 11월 27일
You did not specify your equations or constraints, so I used fminunc. You would have to supply your constraints for fmincon.
However, since it now emerges that you are doing curve-fitting, none of this applies anyway.
So my question is: once i get this 2 equations there is a way to maximize both simultaniusly to find the optimum valors of x1, x2 and x3?
We would have to know significantly more about what you are doing, preferably with some sample data, in order to address that.
Marcellino D'Avino
Marcellino D'Avino 2018년 11월 27일
I'm evalueting the optimum composition of a painting mixture with 3 components, to maximize its hardness and another property ( we call it solids). So i hava set of experimentals data of different composition ( x1,x2, x3 ) and for each of this composition a misured value of hardness and a second property. i fit the data with a quadratic model and so i get 2 equations in the form written above. So my question is: once i get this 2 equations there is a way to maximize both simultaniusly to find the optimum valors of x1, x2 and x3.
I have this costrictions:
50 <x3< 70;
25< x2< 40
5 <x1 <25
those are the experimental data :
2.jpg
Star Strider
Star Strider 2018년 11월 27일
Since you are fitting the data, I would recommend that you use the lsqcurvefit (link) function. It will allow you to fit one or more independent variables to one or more dependent variables, and also accepts bounding constraints on the parameter values. If you post your data in a readable form (not an image), and the functions you want to fit, I will see if I can code lsqcurvefit to estimate the parameters.
thank you very much.
ata=[ 17.5 32.5 50 29 9.539
10 40 50 26 27.33
15 25 60 17 29.21
25 25 50 28 30.46
5 25 70 35 74.98
5 32.5 62.5 31 31.5
11.25 32.5 56.25 21 15.59
5 40 55 20 19.2
18.13 28.75 53.12 29 23.44
8.13 28.75 63.12 25 32.49
25 25 50 19 23.01
15 25 60 14 41.46
10 40 50 30 32.98
5 25 70 23 70.95 ] % experimental data ina readable
x1=data(:,1);
x2=data(:,2);
x3=data(:,3);
y1=data(:,4);
y2=data(:,5);
% the equation to fit in order to determinate the adjustable parameter has to be in this form:
% y = B(1)*x1 + B(2)*x2+ B(3)*x3+ B(4)*x1*x2+ B(5)*x1*x3+B(6)*x2*x3
Please clarify how you want to fit ‘y1’ and ‘y2’. Is it this:
y1 = B(1)*x1 + B(2)*x2+ B(3)*x3+ B(4)*x1*x2+ B(5)*x1*x3+B(6)*x2*x3
y2 = B(1)*x1 + B(2)*x2+ B(3)*x3+ B(4)*x1*x2+ B(5)*x1*x3+B(6)*x2*x3
with the same variables and parameters, or something else?
This is a linear problem, although I cannot determine if the linear solvers can work with multiple dependent variables and constraints, so lsqcurvefit may be the best option.
I have to be away from my computer for a bit, so I will address this in a few minutes.
Marcellino D'Avino
Marcellino D'Avino 2018년 11월 27일
Perfectly. The system is the one you posted before. I'll wait. Thank you so much again
This works, although I am not pleased with the fit. I am confident lsqcurvefit can do better without the parameter constraints.
The Code —
xmtx = data(:,1:3);
ymtx = data(:,4:5);
ub = [25 40 70 Inf Inf Inf];
lb = [ 5 25 50 -Inf -Inf -Inf];
B0 = rand(6,1)*50;
% y = B(1)*x1 + B(2)*x2+ B(3)*x3+ B(4)*x1*x2+ B(5)*x1*x3+B(6)*x2*x3
yfcn = @(B,xmtx) [B(1).*xmtx(:,1) + B(2).*xmtx(:,2)+ B(3).*xmtx(:,3)+ B(4).*xmtx(:,1).*xmtx(:,2)+ B(5).*xmtx(:,1).*xmtx(:,3)+B(6).*xmtx(:,2).*xmtx(:,3), B(1).*xmtx(:,1) + B(2).*xmtx(:,2)+ B(3).*xmtx(:,3)+ B(4).*xmtx(:,1).*xmtx(:,2)+ B(5).*xmtx(:,1).*xmtx(:,3)+B(6).*xmtx(:,2).*xmtx(:,3)];
[estB,resnrm] = lsqcurvefit(yfcn, B0, xmtx, ymtx, lb, ub)
producing:
estB =
23.6459173423105
39.9999999957993
50.0000000036237
3.40010207154624
-2.84490088862063
-2.11343829905202
resnrm =
728324.915961491
Changing ‘B0’ by orders of magnitude does not change the result.
Star Strider
Star Strider 2018년 11월 27일
Marcellino D'Avino’s Answer moved here —
i appreciete your help. thank you again for the time you have spent for me. i don't understand why you use a so large upper and lower bound
My pleasure.
I allowed the constraints for the the variables you did not specify (those being B(4:6)) to be unlimited. If you want to constrain them as well, that is certainly possible. Simply substitute the necessary constraints for the ‘±Inf’ that I used.
Note — You can only constrain parameters, not data. (I assume that you want to constrain the first 3 parameters.) The data are what they are, and you cannot (or at least should not) change them.
If you do not want to constrain the parameters, the lsqcurvefit call becomes:
[estB,resnrm] = lsqcurvefit(yfcn, B0, xmtx, ymtx)
and you should get a much better fit.
If my Answer helped you solve your problem, please Accept it!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Nonlinear Least Squares (Curve Fitting)에 대해 자세히 알아보기

질문:

2018년 11월 27일

댓글:

2018년 11월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by