0% found this document useful (0 votes)
54 views2 pages

If Else For End End: Function

The document defines a function to calculate factorials and uses it to calculate and plot a Taylor series for input value of 3. It first defines a factorial function fact(r) that calculates the factorial of r. It then calculates terms of a Taylor series using factorials and plots the series for values from 0 to 10.

Uploaded by

jaswinder singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views2 pages

If Else For End End: Function

The document defines a function to calculate factorials and uses it to calculate and plot a Taylor series for input value of 3. It first defines a factorial function fact(r) that calculates the factorial of r. It then calculates terms of a Taylor series using factorials and plots the series for values from 0 to 10.

Uploaded by

jaswinder singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

clc

x=poly(0,'x')
function [ll]=fact(r)
f=1
if(r==0)
f=1
else
for i=r:-1:1
f=f*i
end
end

ll=f
endfunction
in=input("Enter the value :")
for j=0:in
p=0
for m=0:20
a=fact(m)
b=fact(m+j)
c=2^(2*m+j)
p=p+((((-1)^m)/(a*b*c))*x.^((2*m)+j))
end

disp(p)
X=[0:0.01:10]
d=horner(p,X)
plot(d)
xgrid()

end
nter the value :3

2 4 6 8 10 12 14 16 18 20 22
24

1 - 0.25x + 0.015625x - 0.0004340x + 0.0000068x - 6.782D-08x + 4.710D-10x - 2.403D-12x +


9.386D-15x - 2.897D-17x + 7.242D-20x - 1.496D-22x + 2.598D-25x

26 28 30 32 34 36 38 40

- 3.843D-28x + 4.902D-31x - 5.446D-34x + 5.319D-37x - 4.601D-40x + 3.550D-43x - 2.459D-46x


+ 1.537D-49x

3 5 7 9 11 13 15 17 19 21 23
25
0.5x - 0.0625x + 0.0026042x - 0.0000543x + 0.0000007x - 5.651D-09x + 3.364D-11x - 1.502D-13x +
5.214D-16x - 1.448D-18x + 3.292D-21x - 6.235D-24x + 9.992D-27x

27 29 31 33 35 37 39 41

- 1.372D-29x + 1.634D-32x - 1.702D-35x + 1.564D-38x - 1.278D-41x + 9.342D-45x - 6.146D-48x


+ 3.658D-51x

2 4 6 8 10 12 14 16 18 20 22 24

0.125x - 0.0104167x + 0.0003255x - 0.0000054x + 5.651D-08x - 4.037D-10x + 2.102D-12x - 8.343D-


15x + 2.607D-17x - 6.584D-20x + 1.372D-22x - 2.398D-25x

26 28 30 32 34 36 38 40 42

+ 3.568D-28x - 4.575D-31x + 5.106D-34x - 5.006D-37x + 4.345D-40x - 3.363D-43x + 2.336D-


46x - 1.463D-49x + 8.315D-53x

3 5 7 9 11 13 15 17 19 21 23
25

0.0208333x - 0.0013021x + 0.0000326x - 0.0000005x + 4.037D-09x - 2.523D-11x + 1.168D-13x -


4.172D-16x + 1.185D-18x - 2.743D-21x + 5.276D-24x - 8.564D-27x

27 29 31 33 35 37 39 41 43

+ 1.189D-29x - 1.430D-32x + 1.502D-35x - 1.390D-38x + 1.143D-41x - 8.408D-45x + 5.561D-


48x - 3.326D-51x + 1.808D-54x

You might also like