Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need to create a m-function that does this: myfirstzero(f,a) which takes two i

ID: 2836361 • Letter: I

Question

I need to create a m-function that does this:

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.

This is what i have now and idk whats wrong with it:

function n = myfirstzero(f,a);
syms x
n = 0;
d=abs(subs(f(x),a));
while(d~=0);
d=subs(diff(f(x),n),a);
n=n+1;
end

Explanation / Answer

Create a MATLAB function file by name myfirstzero.m and write the following MATLAB code to find the value for nth derivative of the given polynomial at the given real number is equal to zero.

function [n] = myfirstzero(f,a)
%Returns the value of n when nth derivative of f at a is equal to 0
l=length(f);   % finds the length of the polynomial
deg=l-1;     % finds the degree of the polynomial
%p=poly(f);
y=polyval(f,a);
n=0;
while(deg>1 && y~=0)
    % perfoms this loop till the required n is found
    f=polyder(f);
    y=polyval(f,a);
    n=n+1;
    deg=deg-1;
end
if y~=0
n=char('No value because all the polynomials are not zero at a');
end
end

The following is the MATLAB output:

>> n=myfirstzero([2 2 1],-0.5)

n =

     1

>> n=myfirstzero([1 3 1 1],-1)

n =

     2

>> n=myfirstzero([1 3 1 1],-2)

n =

No value because all the polynomials are not zero at a

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote