how to create symbolic function for vector input?
Mostra commenti meno recenti
I'm new to Matlab and I wonder how to input a vector to a symbolic function. It is said in the document that creating vectors by x = sym('x',[50 1]) and use it for generate objective function f(x), but it doesn't work if I want to test the value of function when x = ones(50,1) since the input expects 50 variables.
How can I change my code to achieve that?
m = 100;
n = 50;
A = rand(m,n);
b = rand(m,1);
c = rand(n,1);
% initialize objective function
syms x
f = symfun([c'* x - sum(log(A*x + b))],x);
tolerance = 1e-6
% Max iterations
N =1000;
% start point
xstart = ones(n,1)
% Method: gradient descent
% store step history
xg = zeros(n,N);
% initial point
xg(:,1) = xstart;
fprintf('Starting gradient descent.')';
for k = 1:(N-1)
d = - gradient(f,xg(:,k));
if norm(d) < tolearance
xg = xg(:,1:k);
break;
end
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Common Operations in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!