Curve fitting toolbox issue: custom equation produced imaginary part
11 views (last 30 days)
Show older comments
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)
0 Comments
Answers (1)
Kris Fedorenko
on 7 Sep 2017
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
0 Comments
See Also
Categories
Find more on Interpolation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!