The series is infinite but is usually approximated to first few terms. Matlab ha
ID: 3680523 • Letter: T
Question
The series is infinite but is usually approximated to first few terms. Matlab has already a built-in section exp(n) to do this task.
function result = exponential (x)
What is the value returned by your developed function when x = 1 (Answer up to 4 decimal places of accuracy).
y = exponential(1)
y = exponential(4)
Modify your code developed in earlier exercise such that the exponential function can accept a matrix 'm' instead of a number and store the program as exponential_matrix
function y = exponential_matrix(m)
The function calculates the exponential function for all values in the matrix and keep on calculating the terms for each values of matrix till anyone of the term becomes smaller than 0.01. [Remember to add nth term as you did in the previous exercise]
Hint: Use element operations ( .*, ./ and .^) to calculate exponential function for each element of the matrix. The size of input and output matrices will always be the same.
What is the output of
y = exponential_matrix([4 1].
y = expnential_matrix([2 3;4 2])
Explanation / Answer
matlab exponential function code:
function result = exponential(x)
result=1;
n=1;
while(((x^n)/factorial(n))>0.01)
result=result+(x^n)/factorial(n);
n=n+1;
end
result=result+(x^n)/factorial(n);
end
output at command line:
>> exponential(3)
ans =
20.0841
matlab code for exponential_matrix function:
function result = exponential_matrix(x)
result=1;
n=1;
while(((x.^n)./factorial(n))>0.01)
result=result+(x.^n)./factorial(n);
n=n+1;
end
result=result+(x.^n)./factorial(n);
end
output at command line:
>> exponential_matrix([1 2 3 4 5 6])
ans =
2.7167 7.2667 18.4000 42.8667 91.4167 179.8000
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.