이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
random equation fitting to data set and finding constant parameters
조회 수: 2 (최근 30일)
이전 댓글 표시
I have x and y coordinates and I want to fit an equation:
y=a*exp(x^b - 2^b)
to the data set and thus finding parameters a and b. Please help me through it.
채택된 답변
Amit
2014년 1월 22일
First make a function that you'll use to fit like this:
function val = myfunc(par_fit,x,y)
% par_fit = [a b]
val = norm(y - par_fit(1)*exp(x.^2-2^par_fit(2)));
Now, find the parameters like:
my_par = fminsearch(@(par_fit) myfunc(par_fit,x,y),rand(1,2));
댓글 수: 35
aditi
2014년 1월 22일
Hey...thanks for the response...
I am new to matlab...could you please explain the steps so that i can try accordingly..plz
Thanks
aditi
2014년 1월 22일
function val = myfunc(par_fit,x,y)
% par_fit = [a b]
signal=load('mnr.txt');
x=signal(:,1);
y=signal(:,2);
for i=1:length(x)
val = norm(y(i) - par_fit(1)*(exp((x(i))^(par_fit(2)) - (2)^(par_fit(2)))));
%Now, find the parameters like:
my_par = fminsearch(@(par_fit) myfunc(par_fit,x,y),rand(1,2));
end
I did like this and i got the error saying : Input argument "par_fit" is undefined.
Amit
2014년 1월 22일
Okay, I get it. Open a script file and copy:
function val = myfunc(par_fit,x,y)
% par_fit = [a b]
val = norm(y - par_fit(1)*exp(x.^2-2^par_fit(2)));
Save this file as myfunc.m
Now on command window, type
my_par = fminsearch(@(par_fit) myfunc(par_fit,x,y),rand(1,2));
aditi
2014년 1월 22일
okay...the error is gone...but result is not what i wanted
I have x axis values=x y axis values=y
and equation of line to be fit on the plot of data is suppose
d=a*exp(x^b - 2^b)
where a and b i have to find...
so please help according to this
aditi
2014년 1월 22일
hey bruno... could you please explain how above problem can be solved by fit function??
Amit
2014년 1월 22일
Amit
2014년 1월 22일
Your function is y = f(x).
What you are trying is to find the parameters so that (y_you_have - f(x)) is overall minimum (in a least square). This is what you're trying to minimize using fminsearch.
fminsearch tries to minimize the objective value. norm() is like sum((y_you_have - f(x))^2). This should be close to 0 when a and b values are obtained. I hope this is good enough.
aditi
2014년 1월 22일
hey amit...
i just tried on my data set.. the values what this is giving are very less than what are desired...what could be the reason??
also I have to plot d vs x ( where d=a*exp(x^b - 2^b) ) i.e fitted equation over the data set... so what should i do??
Amit
2014년 1월 22일
One the command window in matlab, type:
d = my_par(1)*exp(x.^2-2^my_par(2));
plot(x,y,x,d,'r');
aditi
2014년 1월 22일
in the figure .. blue is the original data set...and red is d vs x...
it does not seem to be a good fit.. :(
what could be done to improve it?
Amit
2014년 1월 22일
Actually my bad:
function val = myfunc(par_fit,x,y)
% par_fit = [a b]
val = norm(y - par_fit(1)*exp(x.^par_fit(2)-2^par_fit(2))); % This was a mistake previously
I made a mistake in reading your equation. Try this. Copy the code in myfunc.m, that I gave you previously.
And for plotting:
d = my_par(1)*exp(x.^my_par(2)-2^my_par(2));
plot(x,y,x,d,'r');
aditi
2014년 1월 22일
equation i corrected... it was just x in place of 2 in first part of bracket...after correcting i got above results... :(
aditi
2014년 1월 22일
i am getting a value suppose 1 which actually should come 5 and am getting b value suppose 1...it should actually be 2...
so m getting very less values than the correct one....same is evident from the figure also..so what could have gone wrong??
aditi
2014년 1월 22일
is there any other method to do this problem???? or what can be corrected in this method itself????
Amit
2014년 1월 22일
is there any chance that that equation is not the right equation for your data set?
If you upload the data, I can give it a try.
aditi
2014년 1월 23일
hey amit
i will give you the data for tested results so that we can cross verify:
4.8000 1.5800
8.0000 1.1500
14.5000 0.9100
22.0000 0.2600
37.0000 0 so 1st column is x axis and second is y
the equation which we have to fit is: a*(x.^(-1/b)) - (37^(-1/b)))
1) find a and b
2) then plot the data and also the fit equation vs x on the same plot to see the fitting
the correct values of parameters are: a=5.47 and b=1.91
please let me know if any othe information is required.
thanks
aditi
2014년 1월 23일
i have attached the .jpg file where equation is shown clearly for above data...because changing the brackets slightly is changing the value of parameters also...so please check n help me out
aditi
2014년 1월 23일
but they are published results...okay i will give you another data set
4.8 0.67
8.0 0.55
14.5 0.09
22.0 0.11
37.0 0.00
and for this equation is same and b value is 1.75..(dont know the a value)
aditi
2014년 1월 23일
and also could you please send me how you wrote that equation??? want to verify if i am using right brackets or not
aditi
2014년 1월 23일
no...there is no exponential...plz see the .jpg file i sent to you...the equation is clear there..
aditi
2014년 1월 23일
i wrote the equation like this:
a*((x.^(-1/b)) - (37^(-1/b)))
i dont know if its correct or not
Amit
2014년 1월 23일
I corrected my mistake in terms of equation. I get very high numbers for a and b. Both values fit the data to some extent (fminsearch fit is better).
No data (from experiments) are perfect. That why one has to be careful when fitting curves. You have limited number of data here (5 points) and your function is highly nonlinear. In estimating parameter, unless data points shows those features due to nonlinearity clearly, you cannot expect a unique parameter estimation. For example, I can fit a linear curve through your data points, and they will fit more or less, alright.
aditi
2014년 1월 23일
ohh..fit luks good...i dint get this... how did you do this??? could you please send me the .m files you made...and also how to plot..?? also what a and b values are you getting??
aditi
2014년 1월 23일
i just showed your plot to my professor and he said it seems fine...and asked me to try on other data sets...and verify...
thanks a lot amit.. could you please once explain how you did the above whole thing...including everything...as m a learner as per MATLAB is concerned...
Thanks :)
Amit
2014년 1월 23일
I did exactly what I told you earlier, just changed it to the new equation you mentioned.
I get values for a and b as, 5.55e7 and 7.12e7. Very Very high from what you said!!
I posted that plot because I wanted to show you that with limited number of data, you cannot estimate parameters for a very nonlinear function. You have to be very careful, especially in research, on how to determine parameters and then trust it.
aditi
2014년 1월 23일
okay...i will follow previous instructions carefully...maybe i have done something wrong...
and a big thanks to u amit...u were of great help :) will contact u if m stuck again somewher else thanks
aditi
2014년 1월 23일
one more thing...what i found after googling is that in such cases u have to give a specific range for 1 of the parameter... so any idea about that..??
like in above equation if i deliberately want that the b value should lie betweem 0.2 and 2 and then find a and b...how can i do that???
추가 답변 (1개)
Matt J
2014년 1월 22일
You might also try FMINSPLEAS. It can take advantage of the fact that y has a linear dependence on one of the parameters 'a'.
댓글 수: 8
aditi
2014년 1월 22일
Hey matt... thanks for the reply...
could you please explain how to use FMINSPLEAS please...
aditi
2014년 1월 22일
hey matt...i am new to matlab...so could you please explain according to my problem...
I have x axis values=x
y axis values=y
and equation of line to be fit on the plot of data is suppose
d=a*exp(x^b - 2^b)
where a and b i have to find...
so please help according to this
Matt J
2014년 1월 22일
If you're new to MATLAB, it makes more sense to start with Amit's solution, which is simpler and which he has given you explicitly.
aditi
2014년 1월 22일
okay... i tried it...but the parameter values are not what i wanted.. so what could have gone wrong..??? also could you please explain the steps of the method which amit told.. i.e what does norm() step is doing...??? why are we subtracting from y???
Matt J
2014년 1월 22일
편집: Matt J
2014년 1월 22일
norm(y - par_fit(1)*exp(x.^2-2^par_fit(2)))
measures the distance between the vector y of given curve samples and the vector
par_fit(1)*exp(x.^2-2^par_fit(2))
of fitted curve samples.
fminsearch tries to find the par_fit(1) and par_fit(2) that minimizes this distance, giving best agreement between y and your parametric curve model.
Walter Roberson
2017년 10월 21일
par_fit is defined in Amit's code, above https://www.mathworks.com/matlabcentral/answers/113318-random-equation-fitting-to-data-set-and-finding-constant-parameters#answer_121842
참고 항목
카테고리
Help Center 및 File Exchange에서 Interpolation에 대해 자세히 알아보기
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)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)