Does someone have the code for Maclaurin function (sinX, cosX, and e^x)?

18 ビュー (過去 30 日間)
aldo angulo
aldo angulo 2018 年 3 月 7 日
コメント済み: Walter Roberson 2019 年 1 月 29 日
I would thank you guys alot

回答 (2 件)

Walter Roberson
Walter Roberson 2018 年 3 月 7 日
syms x
taylor(sin(x),x,0,'Order',10)
taylor(cos(x),x,0,'Order',10)
taylor(exp(x),x,0,'Order',10)
You should be able to deduce the general forms easily. Hint: factorial.

Rishabh Umrao
Rishabh Umrao 2019 年 1 月 29 日
for
function result = MacLaurin(a,n)
% Program to calculate MacLaurin expression
% 'a' is the value whose exponential is to be found
% 'n' is the number of expansion terms
% calculating factorial for the expression
a = cumprod(1:5);
disp(a);
b = 1./a;
vec = 1:5;
d = 0.5.^vec;
c = 1 + sum(d.*b);
result = c;
end
or
function result = MacLaurin1(a,n)
% Program to calculate MacLaurin expression
% 'a' is the value whose exponential is to be found
% 'n' is the number of expansion terms
% calculating factorial for the expression
Res=0;
% loop to calculate factorial and add the element to fact
for i = 0:n
Res = Res + a^i/factorial(i);
end
result = Res;
end
for e^(-x)
% function to calculate MacLaurin series
% 'a' is the value whose exponential is to be found
% 'n' is the number of expansion terms
function result = mclr_lec1_prac_prob_for(n)
terms = [];
for i = 1:n
if (rem(i,2)==0)
terms(i) = (0.25.^i./cumprod(i));
else
terms(i) = -(0.25.^i./cumprod(i));
end
end
expVal = 1+sum(terms);
result = expVal;
end
  2 件のコメント
John D'Errico
John D'Errico 2019 年 1 月 29 日
編集済み: John D'Errico 2019 年 1 月 29 日
Please don't do obvious homework problems for students. Of course, you did nothing for the student, since this question was almost 2 years old now.
Walter Roberson
Walter Roberson 2019 年 1 月 29 日
The first and third of those routines are not correct.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCalculus についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by