How can I differentiate my Function Fun? When I try to use diff it says
'diff'is not supported for class'inline'
The code I used is shown below:
fprintf('Newton Raphson\n');
Fun=input('\nType a function \n');
xi=input('\nType initial value\n');
def=diff(Fun);
der=inline(def);
dxi=der(xi);
Marcin is correct. Don't use
inlinefunctions. Those are no longer used. If you want to differentiate using the Symbolic Math Toolbox, usesymto create a function for you, then use this to differentiate it.As such, do something like this, assuming that
xis the independent variable:Note that because the formula is symbolic, if you want to substitute
xwith a particular value, you would need to usesubs. Withsubs, we are replacingxwith our initial value stored inxi.Let's do a run-through example. Here's what I get when I run this code, with my inputs and outputs:
outwould be the function that was input in:xiwould be the initial value:The derivative of the function is stored in
def:Finally, substituting our initial value into our derivative is stored in
dxi, and thus gives:Good luck!