Hello, I want to solve system of non linear equations using fsolve. There are thre equations and two unknowns K and L. looking at my code, please advice how to best do this. Also please advice if this is the best way or there is an alternate option.

조회 수: 2 (최근 30일)
Ld= 0.8194 %constant
% cos^2(K*L)+ Ld*K*sin(K*L)cos(K*L)=2.2 two non linear equations
% cos^2(K*L)=0.299
% Ld*cos^2(K*L)+sin(K*L)cos(K*L)/K=0.262
cos^2(K*L)+ Ld*K*sin(K*L)cos(K*L)-2.2=0
cos^2(K*L)-0.299=0
Ld*cos^2(K*L)+(sin(K*L)cos(K*L))/K-0.262=0
function F=calib(K,L)
F(1)=cos(K*L)^2+ Ld*K*sin(K*L)*cos(K*L)-2.2;
F(2)=cos(K*L)^2-0.299;
F(3)=Ld*cos^2(K*L)+(sin(K*L)cos(K*L))/K-0.262;
fun = @calib (K,L);
initial_val=[2.73,0.6] % initial value of K and L respectively
x = fsolve(fun,initial_val);
  댓글 수: 2
Star Strider
Star Strider 2018년 5월 25일
In the future, please highlight the code in your questions or comments, then click on the {}Code button to format it.
Sumera Yamin
Sumera Yamin 2018년 5월 28일
Thank you for the guidance. in future i will take care about coding format

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

채택된 답변

Star Strider
Star Strider 2018년 5월 25일
You have the correct approach and are close to the correct solution. There are some errors in your code for ‘calib’ that I corrected. (Check to be certain that they do what you want.) I also created it as an anonymous function, for convenience.
The optimization functions all expect a vector of parameters, not separate parameters. I changed ‘fun’ to provide the correct calling convention, without having to change ‘calib’.
This runs:
Ld= 0.8194 %constant
calib = @(K,L) [cos(K*L).^2 + Ld*K*sin(K*L).*cos(K*L)-2.2; cos(K*L).^2-0.299; Ld*cos(K*L).^2 + (sin(K*L).*cos(K*L))/K-0.262];
fun = @(b) calib(b(1),b(2));
initial_val=[2.73, 0.6] % initial value of K and L respectively
[x,fval] = fsolve(fun,initial_val);
You may need to experiment with it to actually solve your equations, since the end values are not near zero.
  댓글 수: 14
Star Strider
Star Strider 2018년 6월 1일
Not stupid at all. The ga (link) function is the genetic algorithm implementation in the Global Optimization Toolbox.
Walter Roberson
Walter Roberson 2018년 6월 1일
You appear to be trying to match experimental data to theoretical equations as if each entry were exact and the model was perfect. You should instead be looking for parameters that minimize the overall error. For that task, I recommend the Curve Fitting Toolbox.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by