Failure in initial objective function evaluation. LSQNONLIN cannot continue
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Opariuc Andrei
am 6 Dez. 2020
Beantwortet: Walter Roberson
am 6 Dez. 2020
so i'm supposed to do nonlinear regression to find the values of a,b and the equation y given the value of x small x=2.6 .i tried using lsqnonlin but i think i'm doing it wrong ,i don't have anything related to nonlinear regression in my course pdf's and this is the first time i'm attempting lsqnonlin . Additionally i have values of x and the result of the equation y , %X=[0.5 1 2 3 4 ]; %Y=[10.4 5.8 3.3 2.4 2 ]; as an example ,don't have to do anything with them ,and the equation is :
and what i attepmpted is :
%%Input
x=2.6;
y=@(a,b,x)((a+sqrt(x))./(b.*sqrt(x))).^2;
%% calculus
[a,b,y]=lsqnonlin(y,x)
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 6 Dez. 2020
lsqnonlin() is going to pass the given function a single vector of values that is the same length as the second parameter to lsqnonlin(), which is a scalar in your code.
Thus, your y is going to be invoked as y(2.6) so the 2.6 is going to be positionally matched to a and a will be valid inside the function body. However, your y actively uses its second and third parameters, b and x so the function will fail.
Try
y = @(ab) ((ab(1)+sqrt(x))./(ab(2).*sqrt(x))).^2
and pass in an initial vector of length 2
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Linear and Nonlinear Regression finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!