Having issues assigning my output vector in the function below. When I try to call output vector x1(k) I get the error listed. I solved this issue before in my other output 'ex(1)' by using absolute value. Not sure what notation issue is with x1(1).

4 views (last 30 days)
Error at line x1(1) = x + y/jac
In an assignment A(I) = B, the number of elements in B and I must be the same.
function [x1,numIts,ex]=newton(f2,x,maxIts)
% [x,numIts]=newton(func,x,maxIts)
% func is a function handle with signature [y,yprime]=func(x)
N = 10
x = ones(N,1);
x= transpose(x);
x1 = transpose(ones(N,1));
f2 = f1(x);
maxIts=100;
if nargin < 3
maxIts=100; % default value if maxIts is omitted
end
E = 10e-6;
maxIts = 100
k = 2
[y,jac]=f1(x)
y = abs(y(x))
jac = jac(x)
x1(1) = x + y/jac
ex(1) = abs(norm(x - x1(1)))

Answers (0)

Community Treasure Hunt

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

Start Hunting!