How to fit nonlinear data in a curve using the below equation?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Chandrashekar D S
el 23 de Abr. de 2021
Comentada: Chandrashekar D S
el 26 de Abr. de 2021
Hi everyone,
I have a two vector with same demension: CpVector,MyVector :228*1
I am using the below equation as myfun and then using lsqcurvefit to fit the data into a curve. but i am getting error in matrix dimension while plotting.
x0 = [.05, 1, -.05,0.1];
lb = [0, 2, 0.5, -0.6];
ub = [1, -1.5,- 1,1];
myfun_cp = @(x,CpVector) x(1)/(1+x(2).*CpVector) + x(3)/CpVector +x(4);
X = lsqcurvefit(myfun_cp, x0, CpVector, MyVector, lb, ub);
c1=min(CpVector);
c2=max(CpVector);
times=linspace(c1,c2);
plot(Zone_N{1},Zone_N{2},'*r',Zone_A{1},Zone_A{2},'*g',...
Zone_B{1},Zone_B{2},'*black',times,myfun_cp(X,times),'b-');
%zones are just part of the data in CpVector and MyVector
Error using /
Matrix dimensions must agree.
Is the function i am using not correct for curve fitting? if the function is okay then what is the best way/function to use to get desired output.
Below diagram is the data plotted CpVector(X-axis) vs MyVector(Y-axis)
4 comentarios
Adam Danz
el 23 de Abr. de 2021
After adding my answer I see that the error message you shared is different than the error that I received when trying to fit the data with the bounds defined in your question.
Are you sure you've provided us with the correct data?
More importantly, please share the entire error message. Error messages usually contain line numbers that show what line is causing the error.
Respuesta aceptada
Adam Danz
el 23 de Abr. de 2021
The error message is quite clear,
Exiting due to infeasibility: at least one lower bound exceeds the corresponding upper bound.
Looks at the bounds.
>> table(lb(:),ub(:),'VariableNames',{'LowerBound','UpperBound'})
ans =
4×2 table
LowerBound UpperBound
__________ __________
0 1
2 -1.5
0.5 -1
-0.6 1
Two of the parameter lower bounds are higher than the upper bounds!
That's like asking to pick a number greater than 100 but less than 10.
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!