Why do I receive "Error using lsqcurvefit (line 251) Function value and YDATA sizes are not equal."
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
f = ...
[15 25 35 50 65 80];
s = ...
[1070 1602 1931 2100 2041 1876];
plot(f,s,'ro')
title('Data points')
F1 = @(x,xdata)x(1)*sin(xdata*pi/180)*(1-exp(-50*x(2)));
x0 = [1000 0.01];
x1 = lsqcurvefit(F1,x0,f,s)
plot(f,F1(x1,f))
F2 = @(x,xdata)(x(1)*sin(xdata*pi/180)*(1-exp(-50*x(2)))/(1-cos(xdata*pi/180)*exp(-50*x(2))));
x0 = [1000 0.01];
x2 = lsqcurvefit(F2,x0,f,s)
plot(f,F2(x2,f))
%The program works with function F1 but not function F2
2 commentaires
Réponse acceptée
Star Strider
le 3 Août 2021
Do element-wise division
F2 = @(x,xdata)(x(1)*sin(xdata*pi/180)*(1-exp(-50*x(2)))./(1-cos(xdata*pi/180)*exp(-50*x(2))));
↑ ← HERE
and it works!
f = ...
[15 25 35 50 65 80];
s = ...
[1070 1602 1931 2100 2041 1876];
figure
plot(f,s,'ro')
hold on
title('Data points')
F1 = @(x,xdata)x(1)*sin(xdata*pi/180)*(1-exp(-50*x(2)));
x0 = [1000 0.01];
x1 = lsqcurvefit(F1,x0,f,s)
plot(f,F1(x1,f))
F2 = @(x,xdata)(x(1)*sin(xdata*pi/180)*(1-exp(-50*x(2)))./(1-cos(xdata*pi/180)*exp(-50*x(2))));
x0 = [1000 0.01];
x2 = lsqcurvefit(F2,x0,f,s)
plot(f,F2(x2,f),'--')
hold off
legend('Data','F_1','F_2', 'Location','best')
.
.
1 commentaire
Alex Sha
le 5 Août 2021
F1 = @(x,xdata)x(1)*sin(xdata*pi/180)*(1-exp(-50*x(2)));
The above F1 function can be simplified to "F1 = @(x,xdata)x(1)*sin(xdata*pi/180);", with the exactly same result, but avoiding multiple solutions.
For F2 function, the best result should be:
Root of Mean Square Error (RMSE): 14.9218445307446
Sum of Squared Residual: 1335.96866519828
Correlation Coef. (R): 0.999332922291571
R-Square: 0.998666289575811
Parameter Best Estimate
---------- -------------
x1 4323.03442875393
x2 0.00984518829719931
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Descriptive Statistics dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!