Inner matrix dimensions must agree error message,
古いコメントを表示
Hi,
I'm getting an error message that says inner matrix dimensions must agree, but I checked both matrices and they seem fine -- it's just a 2x2 matrix left-multiplying with a 2x1 matrix.
Here's the error message:
Error using *
Inner matrix dimensions must agree.
Error in Root_finding_practice (line 78)
x(:,i+1) = x(:,i) - ( inv( H( x(:, i) ) ) * J( x(:,i) ) ); % Newton's method in 2 variables
And here's the piece of the code:
J = @(x) [ cos( x(2) ), -x(1) * sin( x(2) ) ]; % Jacobian of f
H = @(x) [ 0, -sin( x(2) ); % Hessian matrix of 2nd derivatives
-sin( x(2) ), -cos( x(2) ) * x(1) ];
% An initial guess at a multivariable root:
x = [1; 1];
for i = 1:100 % The for-loop should stop when the function tolerance is satisfied
x(:,i+1) = x(:,i) - ( inv( H( x(:, i) ) ) * J( x(:,i) ) ); % Newton's method in 2 variables
What am I missing?
Thanks,
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Numerical Integration and Differentiation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!