How to change parameters in exp2 fit???

조회 수: 2 (최근 30일)
Alexandra
Alexandra 2013년 7월 28일
Hello, Sorry for the question, im just a very beginner. I am using f=fit(Wavelength_sal_cor(517:1293),Salinity_and_Particle_corrected_spectra(517:1293),'exp2');
It calculate all 4 coefficients, but sometimes I have negative values, then fit is not good, I want to set parameters of second exp as constants 'c' as meaning(at defined x): Salinity_and_Particle_corrected_spectra(998), and d as -0.01. But I don´t understand how to do.
Could you help me please?

답변 (2개)

Shashank Prasanna
Shashank Prasanna 2013년 7월 28일
You can specify a custom model with your requirements instead of using the exp2
model = @(z)z(1)*exp(z(2)*x)+Salinity_and_Particle_corrected_spectra(998)*exp(-0.01*x)
% Where c = Salinity_and_Particle_corrected_spectra(998) and
% d = -0.01
f=fit(Wavelength_sal_cor(517:1293),Salinity_and_Particle_corrected_spectra(517:1293),model);
You could also specify 'StartPoint','Lower' and 'Upper' bounds to get better results.
There are examples in the documentation on how to fit custom models:
  댓글 수: 2
Shashank Prasanna
Shashank Prasanna 2013년 7월 28일
편집: Shashank Prasanna 2013년 7월 28일
Lets forget about your code for a moment. Are you able to run the example in the documentation link I provided without any errors?
If that is working fine then we may need more info about your code.
If the documentation example also shows the same error, you may have a path issue. Try restoredefaultpath
Jon Cherrie
Jon Cherrie 2013년 8월 21일
I think that the anonymous function, model, is not set up correctly for use by Curve Fitting Toolbox. Try this instead:
c = Salinity_and_Particle_corrected_spectra(998);
d = -0.01;
model = @(a, b, x) a*exp( b*x ) + c*exp( d*x );
f = fit( Wavelength_sal_cor(517:1293), Salinity_and_Particle_corrected_spectra(517:1293), model );
To get good results, you will probably need to supply an estimate of the start point, StartPoint.

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


Alexandra
Alexandra 2013년 7월 28일
Thank you for answer! I get ??? Error using ==> subsindex Function 'subsindex' is not defined for values of class 'function_handle'. when trying to fit the model Do you know what does it mean?
  댓글 수: 1
Shashank Prasanna
Shashank Prasanna 2013년 7월 28일
What you posted here is not an answer to your questions but rather a comment to my answer. Please see my reply on the comment to my answer.

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

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by