how to solve the error in Lsqcurvefit
Show older comments
hi guys
i need help for the error i got it , with the function lsqcurvefit, i don't know exactely how to solve this probleme.
Thank you,
this is my script:
clear all
clc
load('RCS1190_460A.mat')
xdata=Times;
i=460
%% RCS1190_460A %%%%%%%%%%%%%%%%%ù
ydata= QC_plusC-45;
fun=@(x,xdata)((x(1)./x(2)).*( 1- (exp(-(x(2)).*xdata))))
x0=[2,1]
x=lsqcurvefit(fun,x0,xdata,ydata)
13 Comments
Torsten
on 14 Apr 2023
Execute
load('RCS1190_460A.mat')
xdata=Times;
i=460;
%% RCS1190_460A %%%%%%%%%%%%%%%%%ù
ydata= QC_plusC-45;
fun=@(x,xdata)((x(1)./x(2)).*( 1- (exp(-(x(2)).*xdata))));
x0=[2,1];
test_y = fun(x0,xdata)
and check whether "test_y" has Inf or NaN elements.
Sou Fat
on 14 Apr 2023
Sou Fat
on 14 Apr 2023
test_y must return a list of values of the same size as your "ydata" and there mustn't be any NaN or Inf values in it.
Any of these conditions cannot be true in your case because lsqcurvefit gets garbage back when it calls "fun" with your xdata and your initial parameter vector x0.
Sou Fat
on 14 Apr 2023
Torsten
on 14 Apr 2023
But it says your objective function returns undefined values at the initial point.
So "test_y" must contain Inf or NaN values.
Sou Fat
on 14 Apr 2023
Sou Fat
on 14 Apr 2023
Try what you get from
any(isnan(fun(x0,xdata)))
any(isinf(fun(x0,xdata)))
If one of them returns 1, you have a problem with the xdata and/or the evaluation of your function.
Do the same for your ydata.
Sou Fat
on 14 Apr 2023
Sou Fat
on 14 Apr 2023
Sou Fat
on 14 Apr 2023
Torsten
on 14 Apr 2023
So no more errors ?
Answers (1)
Sou Fat
on 14 Apr 2023
0 votes
Categories
Find more on Optimization Toolbox 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!