Curve fitting toolbox issue: custom equation produced imaginary part

조회 수: 20 (최근 30일)
Methawi Chomthong
Methawi Chomthong 2017년 8월 31일
답변: Kris Fedorenko 2017년 9월 7일
The fitting tool report this error "Custom equations must produce an output vector, matrix, or array that is the same size and shape as the input data. This custom equation fails to meet that requirement:" I suspected that it was becuase my custom equation could generate non-zero imaginary part, while the actual data I was trying to fit had only real part.
I cannot use 'real' to specify in the custom equation box in the GUI either
This is my equation real(87.68./(1+exp((-1.883-(-a+sqrt(b+c*(0.0172./(x+(1./(0.0101.*log(1.+exp(-0.0101.*(x-(-169.9979)))))))+(-0.0143).*x))))./1.385))+(-80.56)-(-d+sqrt(e+f.*((0.0172/(x+(1/(0.0101*log(1+exp(-0.0101*(x-(-169.9979))))))'))'+(-0.0143)*x))).*(4.00./(1+exp((2.551-(-a+sqrt(b+c*(0.0172./(x+(1./(0.0101.*log(1.+exp(-0.0101.*(x-(-169.9979)))))))+(-0.0143).*x))))./0.415))+(-0.44))./0.92)

답변 (1개)

Kris Fedorenko
Kris Fedorenko 2017년 9월 7일
Hi Methawi!
I was not able to reproduce your error using the " fit " function from the Curve Fitting Toolbox. Which fitting tool are you using?
Here is a simple example using your custom equation to fit a function.
load('simpledata.mat')
customfit = fit(x, data, @(a, b, c, d, e, f, x) custom_eq(a, b, c, d, e, f, x),...
'Robust', 'LAR')
fittedfunc = custom_eq(customfit.a, customfit.b, customfit.c, customfit.d, customfit.e, customfit.f, x);
figure;
plot(x, data, 'o')
hold on
plot(x, fittedfunc)
function y = custom_eq(a, b, c, d, e, f, x)
y = real(87.68./(1+exp((-1.883-(-a+sqrt(b+c*(0.0172./(x+(1./(0.0101.*log(1.+exp(-0.0101.*(x-(-169.9979)))))))+(-0.0143).*x))))./1.385))+(-80.56)-(-d+sqrt(e+f.*((0.0172/(x+(1/(0.0101*log(1+exp(-0.0101*(x-(-169.9979))))))'))'+(-0.0143)*x))).*(4.00./(1+exp((2.551-(-a+sqrt(b+c*(0.0172./(x+(1./(0.0101.*log(1.+exp(-0.0101.*(x-(-169.9979)))))))+(-0.0143).*x))))./0.415))+(-0.44))./0.92);
end

카테고리

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