MATLAB Answers

0

Error: Line 65: J( A = J(w(k,1), w(k,2), w(k,3), w(k,4),w(k,5));

Asked by Carlie Rosenkrance on 11 Nov 2019 at 0:35
Latest activity Answered by Walter Roberson
on 11 Nov 2019 at 1:14
%% Part 4 Problem 16 Methods
% finite difference method
w1 = 1;
w7 = 0 ;
syms w2 w3 w4 w5 w6
f2 = 2*(w1-2*w2+w3)-(0.25).*exp(m);
f3 = 2*(w2-2*w3+w4)-(0.25).*exp(m);
f4 = 2*(w3-2*w4+w5)-(0.25).*exp(m);
f5 = 2*(w4-2*w5+w6)-(0.25).*exp(m);
f6 = 2*(w5-2*w6+w7)-(0.25).*exp(m);
f = [f2, f3, f4, f5, f6];
J = matlabFunction(jacobian(f,[w2,w3,w4,w5,w6]));
F = matlabFunction(f);
tol = 1e-4 ;
kmax = 20 ;
w(1,:) = 400*(ones(1,5));
for k = 1:kmax
A = J(w(k,1), w(k,2), w(k,3), w(k,4),w(k,5)); %ERROR Line 65
b = -F(w(k,1), w(k,2), w(k,3), w(k,4), w(k,5));
if max(abs(b)) < tol
root = w(k,:);
x = 0.25:0.25:1;
break
end
if det(A)==0
break
end
delT = ThomasMethod(A,b);
delT = delT';
w(k+1,:) = w(k,:) + delT;
if norm(delT) < tol
root = w(k+1,:);
x = 0.25:0.25:1
break
end
end

  0 Comments

Sign in to comment.

Tags

Products


Release

R2018a

1 Answer

Answer by Walter Roberson
on 11 Nov 2019 at 1:14

jacobian(f,[w2,w3,w4,w5,w6]) gives a result that does not involve any variables.
When you call matlabFunction, by it builds the input arguments according to symvar() of the expression being converted. When there are no variables in the expression, it builds a function with no inputs.
You can use the 'vars' option of matlabFunction to indicate which variables are to become inputs, even if the variables are not needed for the expression.

  0 Comments

Sign in to comment.