Would anyone be able to help me with this question?
Consider the function:
$f(x) = x \cos(-x^2)$
Write MATLAB functions f.m and fp.m for the function $f$ and its derivative $f '$, respectively.
for the function
function y=f(x) y=x*cos(-x^2); end
and for its derivative
function dy=df(x) dy=cos(x^2)-sin(x^2)*2*x^2; end
if your inputs are vectors then you should change the codes as follows
function y=f(x) y=x.*cos(-x.^2); end
function dy=df(x) dy=cos(x.^2)-sin(x.^2).*2*x.^2; end
Copyright © 2021 JogjaFile Inc.
for the function
and for its derivative
if your inputs are vectors then you should change the codes as follows
and for its derivative