Help with " Attempted to access X(2,1); index out of bounds because numel(X)=1."
Show older comments
Hi, so I just copy the code here... Script:
clc
clear
x1 = sym('x1','real');
x2 = sym('x2','real');
T = [x1 - x2-2;x1^2+x2-2];
J= jmat(T)
x1=1;
x2=1;
%x3=1;
%x4=1;
X = [x1; x2];
[m,n]=size(X)
eps=1e-6;
Y = [];
disp('iteracija x1 x2 F(x1) F(x2) Norma')
fprintf('%5i %11.6f %11.6f\n',0 , X(1,1), X(2,1))
i=1;
while norm(F(T,X(i)))>=eps
X(i+1)=X(i)-DF(J,X(i)^(-1))*F(T,X(i));
norma(i)=norm(F(T,X(:,end)));
fprintf('%5i %11.6f %11.6f %11.6f %11.6f %11.6f \n',i, X(1,end), X(2,end), Y(1,end),Y(2,end), norma(i))
end
function files: jmat.m
function [ R ] = jmat( T )
x1 = sym('x1','real');
x2 = sym('x2','real');
v = [x1, x2];
R= jacobian(T,v);
end
DF.m
function [ R ] = DF( J, X )
x1 = sym('x1','real');
x2 = sym('x2','real');
%x3 = sym('x3','real');
%x4 = sym('x4','real');
R=J;
x1=X(1,1);
x2=X(2,1);
R=eval(R)
end
F.m
function [ Y ] = F( T, X)
x1 = sym('x1','real');
x2 = sym('x1','real');
%x3 = sym('x3','real');
%x4 = sym('x4','real');
Y=T;
x1=X(1,1);
x2=X(2,1);
Y=eval(Y)
end
And the error is:
??? Attempted to access X(2,1); index out of bounds because numel(X)=1.
Error in ==> F at 11 x2=X(2,1);
Error in ==> lygciusistemos at 20 while norm(F(T,X(i)))>=eps
And how the hell X became (1,1) in function, when it was (2,1) in script?
I would really appreciate your help :)
And if there's something you can't understand, tell me :)
Accepted Answer
More Answers (1)
Categories
Find more on Bounding Regions in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!