<jupyter_start><jupyter_text>EXERCISE-1Taylor Polynomials<jupyter_code>import numpy as np
import matplotlib.pyplot as plt

x=np.linspace(-100,100,250)

f1= x/x
f2= 1 + x
f3= 1 + x + x*x/2
f4= 1 + x + x*x/2 + x*x*x/6 
f5= 1 + x + x*x/2 + x*x*x/6 + x*x*x*x/24
f6= 1 + x + x*x/2 + x*x*x/6 + x*x*x*x/24 + x*x*x*x*x/120


plt.plot(x,f1,'g',label=r'$y = 1$')
plt.plot(x,f2,'r',label=r'$y = 1 + x$')
plt.plot(x,f3,'b',label=r'$y = 1 + x + x*x/2$')
plt.plot(x,f4,'y',label=r'$y = 1 + x + x*x/2 + x*x*x/6$')
plt.plot(x,f5,'--',label=r'$y = 1 + x + x*x/2 + x*x*x/6 + x*x*x*x/24 $')
plt.plot(x,f6,'--r',label=r'$y = 1 + x + x*x/2+  x*x*x/6 + x*x*x*x/24 + x*x*x*x*x/120$')

plt.xlabel("X axis")
plt.ylabel("Y axis")
plt.title("TAYLOR POLYNOMIALS")
axes = plt.gca()
axes.set_ylim([-100, 100])
plt.legend()
plt.show()<jupyter_output><empty_output><jupyter_text>EXERCISE-2Newton’s Divided Difference Method<jupyter_code>x=[1,4,6,5]
y=[0,1.386294,1.791759,1.609438]

n=len(x)
def Newton(n,x,y,xp,yp):
  for i in range(0,n):
    f[x[j]]=y[j]
  for i in range(0,n-1):
    for j in range(0,n-i):
      f[<jupyter_output><empty_output><jupyter_text>EXERCISE-4Lagrange Interpolation<jupyter_code>import numpy as np
x=[0,2,4]
y=[1,7.3891,54.5981]
n=len(x)
xp=1
yp=0
def lagrange(n,x,y,xp):
  yp=0
  for i in range(0,n):
    prod=1
    for j in range(0,n):
      if i!=j:
        prod= prod*(xp-x[j])/(x[i]-x[j])
    yp=yp+prod*y[i]
  
  print('Interpolated value at %.f is %.9f.'%(xp,yp))
lagrange(n,x,y,xp)
import numpy as np
x=[2,11/4,4]
y=[1/2,4/11,1/4]
n=len(x)
xp=3
yp=0
def lagrange(n,x,y,xp):
  yp=0
  for i in range(0,n):
    prod=1
    for j in range(0,n):
      if i!=j:
        prod= prod*(xp-x[j])/(x[i]-x[j])
    yp=yp+prod*y[i]
  print('Interpolated value at %.3f is %.9f.'%(xp,yp))
lagrange(n,x,y,xp)
lagrange(n,x,y,1/3)
import numpy as np
x=[200,250,300,350,400,450]
y=[1.708,1.367,1.139,0.967,0.854,0.759]
n=len(x)
xp=330
yp=0
def lagrange(n,x,y,xp):
  yp=0
  for i in range(0,n):
    prod=1
    for j in range(0,n):
      if i!=j:
        prod= prod*(xp-x[j])/(x[i]-x[j])
    yp=yp+prod*y[i]
  print('Interpolated value at %.f is %.9f.'%(xp,yp))
lagrange(n,x,y,xp)<jupyter_output>Interpolated value at 330 is 1.029020608.
{'fraction_non_alphanumeric': 0.2444745151105097, 'fraction_numerical': 0.09336941813261164, 'mean_word_length': 3.9619686800894853, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '85126', 'license': 'MIT', 'n_tokens_mistral': 1315, 'n_tokens_neox': 1198, 'n_words': 202, 'path': 'LAB_9.ipynb', 'repo_name': 'ucpcpu/Numerical-Methods', 'size': '2217'}