필터 지우기
필터 지우기

Solving a non linear least square of a sum function with two unknowns

조회 수: 1 (최근 30일)
Zehra Ese
Zehra Ese 2019년 12월 18일
편집: Matt J 2019년 12월 19일
Hello,
i have a Chi-Square merit function with two unknown k1 and k2. Unfortunately, I don't know exactly which syntax to use to minimize this function in order to determine k1 and k2.
are known, each a vector with 1 column and 17 rows. are constant values.
Unfortunately, I am also relatively new with Matlab. I would be very happy about a step by step explanation. I have already found out that lsqnonlin can be used as a solver.
I appreciate your help. Thank you.
  댓글 수: 2
Star Strider
Star Strider 2019년 12월 18일
Note that lsqnonlin fits a function to data.
Do you have a matching vector for ?
Zehra Ese
Zehra Ese 2019년 12월 19일
Hi,
you're right, I didn't give enough information. Yes its correct I want to fit a function to data. We have given xdata and ydata. g vector contains all measured values. The first term in parantheses is the function we want to fit to the data. I would like to determine and , while minimizing this Chi-square funktion. All the other coefficients are known, as explained before.

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

채택된 답변

Matt J
Matt J 2019년 12월 18일
편집: Matt J 2019년 12월 19일
It would look like this,
kInitial = __________; %initial guess of k
kOptimal = lsqnonlin(@(k) residual(k,am,bm,cm,g,ch,bh,ah) , kInitial); %do the optimization
function r=residual(k,am,bm,cm,g,ch,bh,ah)
k1=k(1); %extract k(i) into separate variables, for convenience
k2=k(2);
numerator=cm+bm*k2+am*k1; %calculate numerator expression for all m
denominator=ch+bh*k2+ah*k1; %calculate demonator expression for all m
r=numerator./denominator - g; %calculate the vector of residuals, for all m
end
  댓글 수: 3
Matt J
Matt J 2019년 12월 19일
Zehra Ese's answer converted to comment:
Thank u so much!!! It looks like it's working. I have to prove the results and I let you know.
Can I ask you to explain the individual steps to me in comments. I am still a beginner in Matlab and would really like to understand that.
Matt J
Matt J 2019년 12월 19일
You're welcome. I've added more comments to the code.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by