Evaluate a function of symbolic variables
Ältere Kommentare anzeigen
I created a function (PV) that depends on a symbolic vector (q1,q2,q3). I would like to evaluate it at some value of the vector but it keeps giving me the general expression in terms of the symbolic vector instead of giving a number. In the end I would like to use fminsearch to minimize the function PV wrt to the symbolic vector (q1,q2,q3).
Thanks in advance.
T=3;
Q = sym('q', [1 T]);
p=1;
c=4;
delta=0.05;
rho=1/(1+delta);
R0=1;
[NETR,Res,PV]=fnsum(T,Q,R0,c,rho,p);
obj = @(q1,q2,q3) -PV;
obj(0.1,0.1,0.1)
function [netrev,R,summm] = fnsum(t,Quant,R1,c,rho,p)
R = sym(1:t+1);
netrev = sym(1:t);
Quant = sym('q', [1 t]);
R(1)=R1;
for i=1:t
netrev(i)= p .* Quant(i) -(c /2).*(Quant(i) .^2)./R(i)
R(i+1)=R(i)-Quant(i);
end
n=1:t;
summm = -sum(((rho).^(n-1)).*(netrev(n)))
end
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Matrices and Arrays finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!