Question: What's wrong with this code? function [ y ] = MyExp( x,n ) % % Function: y = MyExp( x, n ) % Uses the
%
% 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
There are a few issues with this code The calculation of the Taylor series is incorrect The term var... View full answer
Get step-by-step solutions from verified subject matter experts
