Trouble creating function handle with matrices in matlab
이전 댓글 표시
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.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Mathematics and Optimization에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!