Question: What's wrong with this code? function [ y ] = MyExp( x,n ) % % Function: y = MyExp( x, n ) % Uses the

What's wrong with this code?

function [ y ] = MyExp( x,n )
%
% Function: y = MyExp( x, n )
% Uses the Taylor series expansion for exp(x), with n terms,
% to compute an approximation to exp(x).
%
% Input: x = vector containing values at which the exponential is
% to be computed
% n = number of terms in the Taylor series
%
% Output: y = vector, having same length as x, containing exp(x)
% values
%
term = ones(size(x));
y = ones(size(x));
for k = 1:n
term = term .* (x/n);
y = y + term;
end

end 





Step by Step Solution

3.42 Rating (165 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

There are a few issues with this code The calculation of the Taylor series is incorrect The term var... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!