USING MATLAB The function expx can be written as a Taylors s

USING MATLAB

The function exp(x) can be written as a Taylor\'s series by: e^x = 1 + x/1! + x^2/2! + x^3/3! + ... + x^n/n! + ... e^x = 1 + sigma^infinity_n=1 1/n! x^n Write a user-defined function file that calculates exp(x) by using the Taylor\'s series. For the function name and arguments, use y = T exp (x). The input argument x. Chose n = 10 for the number of terms in the series. Compare the output of your function with the output of the MATLAB built-in function using a couple of examples.

Solution

y=1;
x=3;
for n= 1:1:10
y=y+x^n/factorial(n);
end
fprintf(\'by taylor series method %f\ \',y);
fprintf(\'by taylor series method %f\',exp(x));

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

outout

by taylor series method 20.079665
by taylor series method 20.085537>>

_----------------------------------------------------------------------------------

y=1;
x=5;
for n= 1:1:10
y=y+x^n/factorial(n);
end
fprintf(\'by taylor series method %f\ \',y);
fprintf(\'by taylor series method %f\',exp(x));

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

output

by taylor series method 146.380601
by taylor series method 148.413159>>

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

y=1;
x=7;
for n= 1:1:10
y=y+x^n/factorial(n);
end
fprintf(\'by taylor series method %f\ \',y);
fprintf(\'by taylor series method %f\',exp(x));

_-----------------------------------------------------------------------------------

output

by taylor series method 988.591989
by taylor series method 1096.633158>>

USING MATLAB The function exp(x) can be written as a Taylor\'s series by: e^x = 1 + x/1! + x^2/2! + x^3/3! + ... + x^n/n! + ... e^x = 1 + sigma^infinity_n=1 1/n

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site