필터 지우기
필터 지우기

Hi please help me correct this error

조회 수: 1 (최근 30일)
Abdurahman Itani
Abdurahman Itani 2017년 10월 12일
편집: Walter Roberson 2017년 10월 14일
this is the error i am receiving while using the jacobian function,
Error using sym/subs>normalize
Inconsistency between sizes of
second and third arguments.
here is my code
------------------------------------------------------------------------
function [func, j] = sysNonlinearEqs(X) % X here is a vector
clc;
x = X(1)
y = X(2)
z = X(3)
%Define F(x)
syms x y z
func(1,1)= x + y - exp(-z); % Row 1 Column 1 of Vector F(x)
func(2,1)= z + x - exp(-y); % Row 2 Column 1 of Vector F(x)
func(3,1)= y + z - exp(-x); % Row 3 Column 1 of Vector F(x)
% Define Jacobian
J = jacobian(func, [x y z])
j = double(subs(J,{x, y, z}, X))
---------------------------------------------------------
i am trying to call my function in this script and the error message pops up
syms X
%global x y z
% Initial Conditions
X0 = [1; 1; 1];
maxiter = 50;
tolx = 1e-6;
%computation using the Newton Raphson Method
X= X0;
xold = X0;
for i = 1:maxiter
[func,j] = sysNonlinearEqs(X);
X = X- inv(j)*func;
err(:,i) = abs(X-xold);
xold = X;
if ( err(:,i) < tolx)
break;
end
end

채택된 답변

Jonathan Chin
Jonathan Chin 2017년 10월 12일
function [func, j] = sysNonlinearEqs(X)
% X here is a vector clc;
% x = X(1); y = X(2); z = X(3) ;
%Define F(x)
syms x y z
func(1,1)= x + y - exp(-z); % Row 1 Column 1 of Vector F(x)
func(2,1)= z + x - exp(-y); % Row 2 Column 1 of Vector F(x)
func(3,1)= y + z - exp(-x); % Row 3 Column 1 of Vector F(x)
% Define Jacobian
J = jacobian(func, [x y z]) ;
j = double(subs(J,{x, y, z}, X(:).')); %<- X here needs to be in row vector format
  댓글 수: 2
Abdurahman Itani
Abdurahman Itani 2017년 10월 13일
편집: Abdurahman Itani 2017년 10월 13일
i changed the code now the error is
Conversion to logical from sym is not possible.
Error in Main_Script (line 15) if ( err(:,i) < tolx)
can you please help me there?thank you
Jonathan Chin
Jonathan Chin 2017년 10월 14일
err(:,i) is a system of equations, you might need to evaluate those values

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by