How to do Taylor expansion without commands?

6 ビュー (過去 30 日間)
Yulissa Gallardo
Yulissa Gallardo 2022 年 7 月 12 日
編集済み: Yulissa Gallardo 2022 年 7 月 12 日
I want to solve e^x with Taylor series, this is what I have, but I need to replace "factorial"
n = input('ingrese valor de n ');
x = input('ingrese valor de x ');
o=exp(x);
q=n;
w=o*0;
for i= 0:q
w= w + (x.^i)./factorial(n)
plot(x,w)
end
  1 件のコメント
Sam Chak
Sam Chak 2022 年 7 月 12 日
編集済み: Sam Chak 2022 年 7 月 12 日
What is Taylor series? Can you show the formula for the Taylor series of exp(x)?
Once you have the formula of nth order, then I guess the rest will be straightforward, without using command, factorial, and loops.
There must be an integer limit to the nth order that the user can input, isn't it?

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

採用された回答

KSSV
KSSV 2022 年 7 月 12 日
Check the formula for exp(x), you made few mistakes....
n = input('ingrese valor de n ');
x = input('ingrese valor de x ');
s = 0 ;
for i = 0:n
s = s+x^i/myfactorial(i) ;
end
% Check with inbuilt exp
[s exp(x)]
% function for factorial
function a = myfactorial(b)
a = 1 ;
for i = 1:b
a = a*i ;
end
end
  2 件のコメント
Yulissa Gallardo
Yulissa Gallardo 2022 年 7 月 12 日
oooh, I think I understand now, thanks a lot!
KSSV
KSSV 2022 年 7 月 12 日
Thanks is accepting/ voting the answer. :)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by