How to add custom equation for fitting

조회 수: 9 (최근 30일)
Kim Cupang
Kim Cupang 2019년 2월 19일
댓글: hamza ghninou 2021년 1월 24일
hello! I am trying to plot an efficiency curve for a germanium detector, and need to use the following equation for the fit. I dont know how to put this into somethinf matlab can read, Ive tried the sum function but I keep getting errors :/
any help appreciated! Or any other suggestions of how to fit an efficiency curve with another function.
thanks!A11AF7B4-A3B4-44D4-BA22-AAD5D945AB19.jpeg
  댓글 수: 3
John D'Errico
John D'Errico 2021년 1월 24일
편집: John D'Errico 2021년 1월 24일
@hamza ghninou Read my answer. It does solve the problem. Else I would not have posted an answer.
If your question is how to add a custom equation of a different sort using fit, then you could have said so. But then your comment would be most appropriately posed as a separate question, not a comment here, and not even an a n answer to this question as many people would have done.
hamza ghninou
hamza ghninou 2021년 1월 24일
Im so sorry. My bad, I didn't see your answer. Thank you so much.

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

답변 (1개)

John D'Errico
John D'Errico 2019년 2월 19일
편집: John D'Errico 2019년 2월 20일
You are over thinking things, thinking you need to use sum, etc. What is a polynomial model? What do you have?
What are the unknowns? Just a_i?
If so, then this is not even nonlinear, but trivially linear. You can solve it using backslash. Even simpler, you can just use polyfit.
So, assume e is the vector of dependent values, and E the vector of independent values.
A = flip(polyfit(log(E(:)/200),log(e(:)),4));
So one line. The flip at the end allows you to get the coefficients in the order you want them.
Could you have used fit? Of course. In fact, that model is already in the CFT, in the form of 'poly4'. Use it exactly as I did when I called polyfit.
  댓글 수: 1
Kim Cupang
Kim Cupang 2019년 2월 20일
thank you! ill try this right now

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

카테고리

Help CenterFile Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by