How do I fix this error with function handle?
Afficher commentaires plus anciens
Hello,
I've been trying to work through this problem:
Write function myfirstzero(f,a) which takes two inputs:
f: A function handle which you may assume will represent a polynomial.
a: A real number.
Does: Uses a while loop to find the smallest n such f(n)(a) = 0. Note that this means the nth derivative at x = a and note that n = 0 is fair game, where the 0th derivative of a function is just the function itself.
Returns: This value of n.
And my attempt is:
function myfirstzero(f,a)
syms x
n = 0;
d = subs(f(x), a)
while d > 0
d = diff(f(x))
n = n + 1
if d ~= 0
f = matlabFunction(d)
d = f(a)
end
end
n + 1
However, when i put in the input like myfirstzero(@(x) x^3, 2), the function will run fine until it works to d = 6, which I want the function to stop, but it keeps running because d ~= 0, then it errors.
How do I fix this?
Thank you so much, Sea
1 commentaire
Areeba Shahid
le 23 Fév 2020
END: FUNCTION dydt = second_order(t,y,k);
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Common Operations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!