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

1. mypw(a,b) which takes two inputs: a: Either 0 or 1. b: A positive integer. If

ID: 3372637 • Letter: 1

Question


1. mypw(a,b) which takes two inputs:

a: Either 0 or 1.

b: A positive integer.

If a = 0 then use disp to display your %uFB01rst name b times and if a = 1 then use disp to display your

last name b times.

Returns: The value of a.




2. mytaylor(f,a,b,n) which takes 4 inputs:

f: A function handle.

a: A real number.

b: A real number assumed to be close to a.

n: A positive integer.

Approximates f(b) using Pn(b) where Pn(x) is the n

th Taylor Polynomial about x = a using a for

loop to calculate your answer explicitly, do not use any sneaky Matlab functions.

Returns: The answer.



3. mynewton(f,a,n) which takes three inputs:

f: A function handle.

a: A real number.

n: A positive integer.

Approximates an x-intercept of f(x) using a as the starting approximation and proceeding using

Newton-Raphson proceeding through n iterations.

Returns: The %uFB01nal approximation.


guys how do you do this in matlab

Explanation / Answer

I have answered all the 3 questions first and correctly..plz rate me 5 star first....thank you..:)


-----------------------------------------------

function [y]=mypw(a,b)

if a==0

for i=1:b

disp('my first name')

end

else

for i=1:b

disp('my last name')

end

end


y=a;

end



q2)

%in this program i assume f as a polynomial containing the coefficients %of the different degrees of x.



function [y]=mytaylor(f,a,b,n)

y=0;

count=n;

h=b-a;

for i=1:n

if i==1

y=y+polyval(f,a);

else

f=f(1,1:count-1);

for j=1:count-1

f(j)=(count+1-j)*f(j);

end

y=y+polyval(f,h);

end


return y;

end

Q3)function [y]=mynewton(f,a,n)


for i=1:n

y=a-(polyval(f,a)/my_diff(f,a));

a=y;

end


%function my_diff calculated differentiation at point a.


function [y]= my_diff(p,a)

y=0;

l=length(p);

h=0.00000001;

f1=0;

f2=0;

for i=1:l

f1=f1+p(l+1-i)*(a+h)^(i-1);

f2=f2+p(l+1-i)*a^(i-1);

i=i+1;

end


limit=(f1-f2)/h;

y=limit;

end



end