Trouble creating function handle with matrices in matlab
Mostrar comentarios más antiguos
I have a matrix x1 and I am trying to use nlinfit to eventually obtain values of b, b(1) and b(2).
I believe that my function handle is incorrectly doing matrix multiplication, however I cannot figure out what I must do to fix it.
x1 = 0:0.05:1;
x2 = 1-x1;
T = 313.15;
R_const = 8.314;
mdlfunc = @(b,x1) -R_const*T(x1.* log(x1 + b(1).* x2) + x2.* log(x2 + b(2).* x1));
A = 1286.46130;
for i = 1:numel(x1)
gE_exp(i) = A*x1(i)*x2(i);
end
b0 = rand(1,2);
[b,R,J,CovB,MSE] = nlinfit(x1,gE_exp,mdlfunc,b0);
my error message:
Error using nlinfit (line 213)
Error evaluating model function '@(b,x1)-R_const*T(x1.*log(x1+b(1).*x2)+x2.*log(x2+b(2).*x1))'.
Error in Proj1B (line 28)
[b,R,J,CovB,MSE] = nlinfit(x1,gE_exp,mdlfunc,b0)
Caused by:
Array indices must be positive integers or logical values.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Mathematics and Optimization en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!