how to solve the error in Lsqcurvefit

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

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.
I ran your code and found that test_y has a value,
I have the same error you saw it in the picture when i run the code with this "x=lsqcurvefit(fun,x0,xdata,ydata)"
Torsten
Torsten on 14 Apr 2023
Edited: Torsten 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.
exactly what I found a list of value of the same size as my ydata but when i tried to run the function lsqcurvefit, so i don't how to solve this probleme . thank you for your answer
But it says your objective function returns undefined values at the initial point.
So "test_y" must contain Inf or NaN values.
i don't know, look at these picture that when i run the code without lesqcurvefit, it's work
you think i have problem in the ydata ?
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.
i found any(isnan(fun(x0,xdata))) return 1.
and second any(isinf(fun(x0,xdata))) return 0
i did the same for ydata and i found the both return 0
I rectified in the tebalu that it misses a value I rectified it then I verified the two any(isnan(fun(x0,xdata)))
any(isinf(fun(x0,xdata))) and fo ydata which return 0
So no more errors ?

Sign in to comment.

Answers (1)

Sou Fat
Sou Fat on 14 Apr 2023
Yes I didn't find the error thank you for your help

Categories

Tags

Asked:

on 14 Apr 2023

Answered:

on 14 Apr 2023

Community Treasure Hunt

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

Start Hunting!