Error using lsqcurvefit (line 251) Function value and YDATA sizes are not equal.

function F=myFunction(a,x)
F = a(1)*((1800-x)/(1+(((1800-x)/a(2)).^2))-((1800+x)/(1+(((1800+x)/a(2)).^2))))-a(3);
end
t = [0.1468; 0.1466; 0.1464; 0.1474; 0.1485; 0.1495; 0.1514; 0.1526; 0.1534; 0.1530; 0.1528; 0.1532; 0.1533; 0.1536; 0.1534; 0.1535; 0.1536; 0.1537; 0.1539; 0.1541; 0.1548];
v = [122.74; 122.66; 122.28; 122.23; 122.25; 122.02; 121.5; 122.15; 122.2; 121.46; 121.3; 120.5; 120.35; 120.12; 120.09; 119.9; 119.7; 119.4; 119.2; 118.8; 118.6];
%plot(t,v,'ro')
%xlabel('torque, Nm')
%ylabel('motor speed, rpm')
%title('Torque vs Motor Speed')
%hold on
size(
a0 = [1 1 0];
[a,resnorm,~,exitflag,output] = lsqcurvefit(@myFunction,a0,t,v);

Answers (1)

function F=myFunction(a,x)
F = a(1)*(1800-x)./(1+((1800-x)/a(2)).^2)-(1800+x)./(1+((1800+x)/a(2)).^2)-a(3);
end
And maybe you will have to change t and v into row vectors.
Best wishes
Torsten.

Products

Asked:

on 4 Dec 2017

Answered:

on 4 Dec 2017

Community Treasure Hunt

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

Start Hunting!