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
inline
functions. Those are no longer used. If you want to differentiate using the Symbolic Math Toolbox, usesym
to create a function for you, then use this to differentiate it.As such, do something like this, assuming that
x
is the independent variable:Note that because the formula is symbolic, if you want to substitute
x
with a particular value, you would need to usesubs
. Withsubs
, we are replacingx
with 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:
out
would be the function that was input in:xi
would 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!