MATLAB: How to evaluate symbolic derivative

derivativediff()evalfunctionMATLABsymbolicSymbolic Math Toolboxsyms

I have created a function, powerdiff, but when I try to evaluate it at a number I get the following error message. I am wanting to evaluate it at different points to try and find the root:
Subscript indices must either be real positive integers or logicals.
Error in sym/subsref (line 805)
R_tilde = builtin('subsref',L_tilde,Idx);
Error in ivcurve_var_zoom (line 36)
powerdiff(1e-2)
Here is my code. I can evaluate the original function, power, just not powerdiff (the derivative).
syms J
Veff=@(J)0;
%Creating voltage equation
for i=1:numbg
Jph=flux(i,2);%Constant

Avalue=A(i);%Constant
V=@(J)k*t*log((Jph-J)/Avalue)+bg(i);%Voltage function
Veff=@(J)Veff(J)+V(J);%Adds to previous voltage function
end
power=@(J)Veff(J).*J;
power(1e-2)
powerdiff=diff(power(J));
powerdiff(1e-2)

Best Answer

Hi,
you are treating the derivate like the function handle - but it is not a function handle.
What you do is asking matlab for the value of the vector powerdiff at the index 1e-2...
What you probably want to do is get the result of that function for the input value 1e-2.
You could use matlabFunction to achieve what you want.
Best regards
Stephan
Related Question