Maximize a system of nonlinear equation
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
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
2018년 11월 27일
If you want more than blind suggestions, we would need to see your code.
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
2018년 11월 27일
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
i don't understand. I can use with fminunc the same option of fmincon?
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.
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 :

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.
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
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)에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
