Input type error symbolic tool kit

I just installed symbolic tool kit and not familiar with it.
I am using Steepest Descent Method to solve a system. Following is my code:
syms x1 x2 x3
f =@(x1,x2,x3) (x1^3+x1^2*x2-x1*x3+6)^2+(exp(x1)+exp(x2)-x3)^2+(x2^2-2*x1*x3-4)^2;
syms phi(t)
x0 = [1 1 1];
change = 1;
xi = x0;
g = gradient(f,[x1 x2 x3]);
kk=1;
eps=1e-05;
while change > eps
gt = double(subs(g, [x1,x2,x3], xi));
if gt == 0
break;
end
tt = xi - t*gt';
phi = (subs(f, [x1,x2,x3], tt));
phi = symfun(phi, t);
phi(t) = simplify(phi);
phi_dash = diff(phi);
ti = solve(phi_dash, t);
ti = double(ti);
im = imag(ti);
re = real(ti);
ri = im./re;
ti(ri>1e-3) = [];
ti = real(ti);
temp = double(phi(ti));
[~, te] = min(abs(temp));
ti = ti(te);
xt = xi;
xi = xi - ti*gt';
change = (xi-xt)*(xi-xt)';
error(kk)=change;
kk=kk+1;
end
kk=1:kk-1;
plot(kk,error)
xlabel('Iteration')
ylabel('Error')
title('Plot showing Error convergence')
disp(strrep(['Solution is: [' num2str(xi, ' %0.2d') ']'], ',)', ')'))
It runs on r2016a with lots of warnings but I am using r2019a at home and I am getting the following error
Error using subs
Expected input number 1, S, to be one of these types:
sym
Instead its type was function_handle.
Error in sym/subs (line 60)
validateattributes(F, {'sym'}, {}, 'subs', 'S', 1);
Error in (line 20)
phi = (subs(f, [x1,x2,x3], tt));
I am downloading r2016a now but it's really slow and I'd like to debug this to run on r2019a.
Please help!

回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by