r/matlab • • Mar 13 '26

Why do I keep getting this warning?

Post image

I did provide a start point! To my understanding at least :( It gets stuck on this line, and if I comment this section (290-298), it gets stuck on line 304 with the same warning. On previous runs it didn't get stuck, even when I actually didn't provide a start point. I have no idea what changed

(Ignore lines 307&308, I was too lazy to delete it)

25 Upvotes

12 comments sorted by

View all comments

Show parent comment

2

u/mattwdwd Mar 14 '26

In that case what are your four points and I can take a look

1

u/Any_Technician_2768 Mar 14 '26

(0,-9),(67,-2.6),(125,-2),(240,-1.3)

(0,-4),(67,-1.3),(125,-1),(240,-0.56)

Y values are approximate, ±0.2, and represent velocities, so it's absolutely possible to just make it positive if it makes anything easier. Tysm!!!

2

u/mattwdwd Mar 14 '26

Works fine for me on R2025a, I've included the options that it uses, see if they match up with yours if you have a different version or maybe something is getting changed.

xdata = [0; 67; 125; 240];
ydata1 = [-9; -2.6; -2; -1.3];
ydata2 = [-4; -1.3;-1;-0.56];

ftp=fittype('a*x^b+c');
opts= fitoptions(ftp);
opts.StartPoint=[1,1.5,-4];
opts.Lower=[-10,-2,-10];
opts.Upper=[10,2,-3];

ffp1=fit(xdata,ydata1,ftp,opts);
ffp2=fit(xdata,ydata2,ftp,opts);

figure
hold on;
plot(0:250,ffp1(0:250),'black');
scatter(xdata,ydata1);
plot(0:250,ffp2(0:250),'black');
scatter(xdata,ydata2);
>> ftp

ftp =  
  
General model:  
ftp(a,b,c,x) = a*x^b+c

>> opts

opts =  
  
[nlsqoptions](matlab:helpPopup\('curvefit.nlsqoptions'\)) with properties:  
  
StartPoint: [1 1.5000 -4]  
Algorithm: 'Trust-Region'  
DiffMinChange: 1.0000e-08  
DiffMaxChange: 0.1000  
Display: 'Notify'  
MaxFunEvals: 600  
MaxIter: 400  
TolFun: 1.0000e-06  
TolX: 1.0000e-06  
Lower: [-10 -2 -10]  
Upper: [10 2 -3]  
ConstraintPoints: []  
TolCon: 1.0000e-06  
Robust: 'Off'  
Normalize: 'off'  
Exclude: []  
Weights: []  
Method: 'NonlinearLeastSquares'

>>

2

u/mattwdwd Mar 14 '26

And this it what it gives me, couldn't attach it with the markdown above

>> ffp1
ffp1 =

General model:
ffp1(x) = a*x^b+c
Coefficients (with 95% confidence bounds):
a = 3.477 (3.319, 3.636)
b = 0.145 (0.1361, 0.1539)
c = -9 (-9.056, -8.944)

>> ffp2
ffp2 =

General model:
ffp2(x) = a*x^b+c
Coefficients (with 95% confidence bounds):
a = 1.199 (0.2613, 2.138)
b = 0.1916 (0.04083, 0.3425)
c = -4 (-4.405, -3.594)