What's wrong with this code? function [ y ] = MyExp( x,n ) % % Function: y
Fantastic news! We've Found the answer you've been seeking!
Question:
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
%
% 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
Related Book For
Elementary Linear Algebra with Applications
ISBN: 978-0471669593
9th edition
Authors: Howard Anton, Chris Rorres
Posted Date: