Curve Fitting Toolbox Error: This expression has no coefficients or non-scalar coefficients.

Hi, i want to use the curve fitter with the custome equation:
y(x)=y0*((sin(n*a*(sin(x)/b)*pi))/sin(a*(sin(x)/b)*pi))^2*sinc((sin(x)/b)*pi*c)^2 with n = 5; a = 30e-6; b = 450e-9; c = 450e-9
My data has the following form:
0;3140
1;3073
...
24;3232
25;3349
I always recieve the error message
Fit Name: untitled fit 1
Error: This expression has no coefficients or non-scalar coefficients.
Warning: Ignoring NaNs in data.

10 Kommentare

Does your data exhibit this oscillatory pattern?
x = linspace(0, 25, 2501);
n = 5;
a = 30e-6;
b = 450e-9;
c = 450e-9;
y0 = 3140/25;
y = y0*((sin(n*a*(sin(x)/b)*pi))./sin(a*(sin(x)/b)*pi)).^2.*sinc((sin(x)/b)*pi*c).^2;
plot(x, y), grid on
xlabel('x')
ylabel('y')
I always recieve the error message
Receive from what? You ahven't shown us what you did.
@Sam Chak Yes, the data looks like this. I attached the txt file with the sample data and a screenshot below. In this example n = 3, a = approx. 30e-6; b = 532e-9; c = 532e-9, but this is not really the thing tuning the details. I just cant get the fit to start at all. :(
@Matt J I attached one attempt below.
The function 57857*((sin(5*30e-6*(sin(x)/450e-9)*pi))/sin(30e-6*(sin(x)/450e-9)*pi))^2*sinc((sin(x)/450e-9)*pi*5e-6)^2 e.g. is not working if i use letters it also is not. I always recieve the msg: "Error: This expression has no coefficients or non-scalar coefficients."
Thanks for the advice.
I'm confused about what you are trying to accomplish here.
If you know the values of all the parameters of your equation (n = 5; a = 30e-6; b = 450e-9; c = 450e-9), then how is this a curve-fitting problem?
Are you trying to fit this with some other equation, that you don't know the parameters of? If so, you need that other equation.
The function 57857*((sin(5*30e-6*(sin(x)/450e-9)*pi))/sin(30e-6*(sin(x)/450e-9)*pi))^2*sinc((sin(x)/450e-9)*pi*5e-6)^2 e.g. is not working if i use letters it also is not. I always recieve the msg: "Error: This expression has no coefficients or non-scalar coefficients."
What coefficients do you want Curve Fitting Toolbox to fit in that equation? x is the independent variable. pi is a function in MATLAB, as is sin. sinc is a function in Signal Processing Toolbox. So they're not coefficients. Everything else is a literal number.
What "knobs" does Curve Fitting Toolbox get to turn to try to make your equation fit your data?
Sorry, maybe something got lost in the translation. My English math skills are not the best.
The function I try to fit looks like this, now I eliminated sinc^2 with sin^2(x)/(x)^2.
The dataset (sample-data.txt) is what i try to fit the function to.
Maybe the better question is then: How can I fit the function above to the sample-data.txt in MATLAB, maybe with using the curve fitting toolbox?
This didn´t work for me if I wrote this function like this in the curve fitting toolbox I recieved the same error. I got desprate and tried estimating some variables in guessing them and writing them into the tool :/.
Is N restricted to integer valued, or is it a constant?
@Walter Roberson If possible, N should be an integer. If not, N could be set by the number of main spikes of the data points. For example, I think it should be 3 for this one.
What do you know and what are the parameters that Curve Fitting Toolbox can adjust to fit the equation to the data?
Knowns:
  • x is the independent variable
  • y is the dependent variable
Not sure if known or parameter:
  • y0
  • N
  • d
  • λ
  • b
You may also need to be careful to avoid division by 0: lambda can't be 0, x can't be a multiple of pi, etc.
The curve fitting toolbox does not handle restriction of a parameter to be an integer.
It would be better if you counted the pulses first and used that as your N.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

As has been pointed out, you have to give the app some coeffients to adjust to try to fit to. Also note that your proposed coefficient values are extremely small. You will need to do some tweaking of fit settings to get results at that scale.
The other challenge you will have is that the equation evaluates to NaN at y=0, which will also throw an error.
Try this to at least get rid of the errors.
% Equation
3140*(((sin(5.*a.*(sin(x)./b).*pi))./sin(a.*(sin(x)./b).*pi)).^2).*(sinc((sin(x)./b).*pi.*c).^2);
  • Add an exclusion rule to ignore x<1.
At this point, the curve fitter should start fillting a,b, and c. The results I get are not very good, though.

1 Kommentar

Despite the proposed fitting model being undefined (NaN) at , both the left-hand and right-hand limits as exist and are equal.
syms a b c N x y0
f = y0*(((sin(N*a*(sin(x)/b)*pi))/sin(a*(sin(x)/b)*pi))^2)*(sinc((sin(x)/b)*pi*c)^2)
f = 
limit(f, x, 0)
ans = 
If the fitting model is intended to be continuous at 0, then it must satisfy based on the data point .

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Get Started with Curve Fitting Toolbox finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2025b

Gefragt:

am 13 Okt. 2025

Kommentiert:

am 14 Okt. 2025

Community Treasure Hunt

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

Start Hunting!

Translated by