Problem 1

seq(from = 0, to = (5/2)^(1/2), by = (((5/2)^(1/2))/500))
##   [1] 0.000000000 0.003162278 0.006324555 0.009486833 0.012649111 0.015811388
##   [7] 0.018973666 0.022135944 0.025298221 0.028460499 0.031622777 0.034785054
##  [13] 0.037947332 0.041109610 0.044271887 0.047434165 0.050596443 0.053758720
##  [19] 0.056920998 0.060083276 0.063245553 0.066407831 0.069570109 0.072732386
##  [25] 0.075894664 0.079056942 0.082219219 0.085381497 0.088543774 0.091706052
##  [31] 0.094868330 0.098030607 0.101192885 0.104355163 0.107517440 0.110679718
##  [37] 0.113841996 0.117004273 0.120166551 0.123328829 0.126491106 0.129653384
##  [43] 0.132815662 0.135977939 0.139140217 0.142302495 0.145464772 0.148627050
##  [49] 0.151789328 0.154951605 0.158113883 0.161276161 0.164438438 0.167600716
##  [55] 0.170762994 0.173925271 0.177087549 0.180249827 0.183412104 0.186574382
##  [61] 0.189736660 0.192898937 0.196061215 0.199223493 0.202385770 0.205548048
##  [67] 0.208710326 0.211872603 0.215034881 0.218197159 0.221359436 0.224521714
##  [73] 0.227683992 0.230846269 0.234008547 0.237170825 0.240333102 0.243495380
##  [79] 0.246657657 0.249819935 0.252982213 0.256144490 0.259306768 0.262469046
##  [85] 0.265631323 0.268793601 0.271955879 0.275118156 0.278280434 0.281442712
##  [91] 0.284604989 0.287767267 0.290929545 0.294091822 0.297254100 0.300416378
##  [97] 0.303578655 0.306740933 0.309903211 0.313065488 0.316227766 0.319390044
## [103] 0.322552321 0.325714599 0.328876877 0.332039154 0.335201432 0.338363710
## [109] 0.341525987 0.344688265 0.347850543 0.351012820 0.354175098 0.357337376
## [115] 0.360499653 0.363661931 0.366824209 0.369986486 0.373148764 0.376311042
## [121] 0.379473319 0.382635597 0.385797875 0.388960152 0.392122430 0.395284708
## [127] 0.398446985 0.401609263 0.404771541 0.407933818 0.411096096 0.414258373
## [133] 0.417420651 0.420582929 0.423745206 0.426907484 0.430069762 0.433232039
## [139] 0.436394317 0.439556595 0.442718872 0.445881150 0.449043428 0.452205705
## [145] 0.455367983 0.458530261 0.461692538 0.464854816 0.468017094 0.471179371
## [151] 0.474341649 0.477503927 0.480666204 0.483828482 0.486990760 0.490153037
## [157] 0.493315315 0.496477593 0.499639870 0.502802148 0.505964426 0.509126703
## [163] 0.512288981 0.515451259 0.518613536 0.521775814 0.524938092 0.528100369
## [169] 0.531262647 0.534424925 0.537587202 0.540749480 0.543911758 0.547074035
## [175] 0.550236313 0.553398591 0.556560868 0.559723146 0.562885424 0.566047701
## [181] 0.569209979 0.572372256 0.575534534 0.578696812 0.581859089 0.585021367
## [187] 0.588183645 0.591345922 0.594508200 0.597670478 0.600832755 0.603995033
## [193] 0.607157311 0.610319588 0.613481866 0.616644144 0.619806421 0.622968699
## [199] 0.626130977 0.629293254 0.632455532 0.635617810 0.638780087 0.641942365
## [205] 0.645104643 0.648266920 0.651429198 0.654591476 0.657753753 0.660916031
## [211] 0.664078309 0.667240586 0.670402864 0.673565142 0.676727419 0.679889697
## [217] 0.683051975 0.686214252 0.689376530 0.692538808 0.695701085 0.698863363
## [223] 0.702025641 0.705187918 0.708350196 0.711512474 0.714674751 0.717837029
## [229] 0.720999307 0.724161584 0.727323862 0.730486139 0.733648417 0.736810695
## [235] 0.739972972 0.743135250 0.746297528 0.749459805 0.752622083 0.755784361
## [241] 0.758946638 0.762108916 0.765271194 0.768433471 0.771595749 0.774758027
## [247] 0.777920304 0.781082582 0.784244860 0.787407137 0.790569415 0.793731693
## [253] 0.796893970 0.800056248 0.803218526 0.806380803 0.809543081 0.812705359
## [259] 0.815867636 0.819029914 0.822192192 0.825354469 0.828516747 0.831679025
## [265] 0.834841302 0.838003580 0.841165858 0.844328135 0.847490413 0.850652691
## [271] 0.853814968 0.856977246 0.860139524 0.863301801 0.866464079 0.869626357
## [277] 0.872788634 0.875950912 0.879113190 0.882275467 0.885437745 0.888600023
## [283] 0.891762300 0.894924578 0.898086855 0.901249133 0.904411411 0.907573688
## [289] 0.910735966 0.913898244 0.917060521 0.920222799 0.923385077 0.926547354
## [295] 0.929709632 0.932871910 0.936034187 0.939196465 0.942358743 0.945521020
## [301] 0.948683298 0.951845576 0.955007853 0.958170131 0.961332409 0.964494686
## [307] 0.967656964 0.970819242 0.973981519 0.977143797 0.980306075 0.983468352
## [313] 0.986630630 0.989792908 0.992955185 0.996117463 0.999279741 1.002442018
## [319] 1.005604296 1.008766574 1.011928851 1.015091129 1.018253407 1.021415684
## [325] 1.024577962 1.027740240 1.030902517 1.034064795 1.037227073 1.040389350
## [331] 1.043551628 1.046713906 1.049876183 1.053038461 1.056200738 1.059363016
## [337] 1.062525294 1.065687571 1.068849849 1.072012127 1.075174404 1.078336682
## [343] 1.081498960 1.084661237 1.087823515 1.090985793 1.094148070 1.097310348
## [349] 1.100472626 1.103634903 1.106797181 1.109959459 1.113121736 1.116284014
## [355] 1.119446292 1.122608569 1.125770847 1.128933125 1.132095402 1.135257680
## [361] 1.138419958 1.141582235 1.144744513 1.147906791 1.151069068 1.154231346
## [367] 1.157393624 1.160555901 1.163718179 1.166880457 1.170042734 1.173205012
## [373] 1.176367290 1.179529567 1.182691845 1.185854123 1.189016400 1.192178678
## [379] 1.195340956 1.198503233 1.201665511 1.204827789 1.207990066 1.211152344
## [385] 1.214314622 1.217476899 1.220639177 1.223801454 1.226963732 1.230126010
## [391] 1.233288287 1.236450565 1.239612843 1.242775120 1.245937398 1.249099676
## [397] 1.252261953 1.255424231 1.258586509 1.261748786 1.264911064 1.268073342
## [403] 1.271235619 1.274397897 1.277560175 1.280722452 1.283884730 1.287047008
## [409] 1.290209285 1.293371563 1.296533841 1.299696118 1.302858396 1.306020674
## [415] 1.309182951 1.312345229 1.315507507 1.318669784 1.321832062 1.324994340
## [421] 1.328156617 1.331318895 1.334481173 1.337643450 1.340805728 1.343968006
## [427] 1.347130283 1.350292561 1.353454839 1.356617116 1.359779394 1.362941672
## [433] 1.366103949 1.369266227 1.372428505 1.375590782 1.378753060 1.381915337
## [439] 1.385077615 1.388239893 1.391402170 1.394564448 1.397726726 1.400889003
## [445] 1.404051281 1.407213559 1.410375836 1.413538114 1.416700392 1.419862669
## [451] 1.423024947 1.426187225 1.429349502 1.432511780 1.435674058 1.438836335
## [457] 1.441998613 1.445160891 1.448323168 1.451485446 1.454647724 1.457810001
## [463] 1.460972279 1.464134557 1.467296834 1.470459112 1.473621390 1.476783667
## [469] 1.479945945 1.483108223 1.486270500 1.489432778 1.492595056 1.495757333
## [475] 1.498919611 1.502081889 1.505244166 1.508406444 1.511568722 1.514730999
## [481] 1.517893277 1.521055555 1.524217832 1.527380110 1.530542388 1.533704665
## [487] 1.536866943 1.540029221 1.543191498 1.546353776 1.549516053 1.552678331
## [493] 1.555840609 1.559002886 1.562165164 1.565327442 1.568489719 1.571651997
## [499] 1.574814275 1.577976552 1.581138830
x= seq(0, (5/2)^(1/2), length = 200)
y = tan(sin(x**3))
#
plot(x, y,
type = "l",
lty = 1,
lwd = 2,
col = "blue",
xlab = "X",
ylab = "Y",
main = "The curve of y = tan(sin(x^3))")
abline(h = 0, lty = 2, lwd = 1, col = "darkred")

Now mathematically find the roots of f(x) tan = 0 when sin of x^3 = 0 sin is 0 at pi and 0 so the roots have to be x=0 and x= (pi)^(1/3) which is approximately 1.46 First find the derivative of f(x) f’(x)= cos(x^3) * (3 * x2)/cos(sin(x3))^2

# Define f(x) and f'(x)

fn = function(x) tan(sin(x**3))
dfn = function(x) cos(x^3) * (3 * x^2)/cos(sin(x^3))^2

# initial values
n = 0
x = -1
M = 200
TOL = 10^(-6)
ERR = abs(fn(x)/dfn(x))
# loop begins
while(ERR > TOL){
  n = n + 1
  x = x - fn(x)/dfn(x)
  ERR = abs(fn(x)/dfn(x))
  if(ERR < TOL){
     cat("\n\nAlgorithm converges!")
     cat("\nThe approximated root:", x, ".")
     cat("\nThe absolute error:", ERR, ".")
     cat("\nThe number of iterations n =",n,".")
     break
    } else{
      cat("\nIteration n =",n, ", approximate root:",x,", absolute error:", ERR,".")
    } 
    if (n ==M){
      cat("\n\nThe maximum iterations attained!")
      cat("\nThe algorithm did not converge!")
      break
    }
}
## 
## Iteration n = 1 , approximate root: -0.6934684 , absolute error: 0.2233353 .
## Iteration n = 2 , approximate root: -0.4701332 , absolute error: 0.1561519 .
## Iteration n = 3 , approximate root: -0.3139813 , absolute error: 0.104627 .
## Iteration n = 4 , approximate root: -0.2093543 , absolute error: 0.06978279 .
## Iteration n = 5 , approximate root: -0.1395715 , absolute error: 0.04652371 .
## Iteration n = 6 , approximate root: -0.09304776 , absolute error: 0.03101591 .
## Iteration n = 7 , approximate root: -0.06203184 , absolute error: 0.02067728 .
## Iteration n = 8 , approximate root: -0.04135456 , absolute error: 0.01378485 .
## Iteration n = 9 , approximate root: -0.02756971 , absolute error: 0.009189903 .
## Iteration n = 10 , approximate root: -0.01837981 , absolute error: 0.006126602 .
## Iteration n = 11 , approximate root: -0.0122532 , absolute error: 0.004084401 .
## Iteration n = 12 , approximate root: -0.008168803 , absolute error: 0.002722934 .
## Iteration n = 13 , approximate root: -0.005445868 , absolute error: 0.001815289 .
## Iteration n = 14 , approximate root: -0.003630579 , absolute error: 0.001210193 .
## Iteration n = 15 , approximate root: -0.002420386 , absolute error: 0.0008067953 .
## Iteration n = 16 , approximate root: -0.001613591 , absolute error: 0.0005378636 .
## Iteration n = 17 , approximate root: -0.001075727 , absolute error: 0.0003585757 .
## Iteration n = 18 , approximate root: -0.0007171514 , absolute error: 0.0002390505 .
## Iteration n = 19 , approximate root: -0.0004781009 , absolute error: 0.000159367 .
## Iteration n = 20 , approximate root: -0.000318734 , absolute error: 0.0001062447 .
## Iteration n = 21 , approximate root: -0.0002124893 , absolute error: 7.082977e-05 .
## Iteration n = 22 , approximate root: -0.0001416595 , absolute error: 4.721985e-05 .
## Iteration n = 23 , approximate root: -9.443969e-05 , absolute error: 3.14799e-05 .
## Iteration n = 24 , approximate root: -6.295979e-05 , absolute error: 2.09866e-05 .
## Iteration n = 25 , approximate root: -4.19732e-05 , absolute error: 1.399107e-05 .
## Iteration n = 26 , approximate root: -2.798213e-05 , absolute error: 9.327377e-06 .
## Iteration n = 27 , approximate root: -1.865475e-05 , absolute error: 6.218251e-06 .
## Iteration n = 28 , approximate root: -1.24365e-05 , absolute error: 4.145501e-06 .
## Iteration n = 29 , approximate root: -8.291002e-06 , absolute error: 2.763667e-06 .
## Iteration n = 30 , approximate root: -5.527334e-06 , absolute error: 1.842445e-06 .
## Iteration n = 31 , approximate root: -3.68489e-06 , absolute error: 1.228297e-06 .
## 
## Algorithm converges!
## The approximated root: -2.456593e-06 .
## The absolute error: 8.188644e-07 .
## The number of iterations n = 32 .
# Define f(x) and f'(x)

fn = function(x) tan(sin(x**3))
dfn = function(x) cos(x^3) * (3 * x^2)/cos(sin(x^3))^2

# initial values
n = 0
x = 1.58
M = 200
TOL = 10^(-6)
ERR = abs(fn(x)/dfn(x))
# loop begins
while(ERR > TOL){
  n = n + 1
  x = x - fn(x)/dfn(x)
  ERR = abs(fn(x)/dfn(x))
  if(ERR < TOL){
     cat("\n\nAlgorithm converges!")
     cat("\nThe approximated root:", x, ".")
     cat("\nThe absolute error:", ERR, ".")
     cat("\nThe number of iterations n =",n,".")
     break
    } else{
      cat("\nIteration n =",n, ", approximate root:",x,", absolute error:", ERR,".")
    } 
    if (n ==M){
      cat("\n\nThe maximum iterations attained!")
      cat("\nThe algorithm did not converge!")
      break
    }
}
## 
## Iteration n = 1 , approximate root: 1.484744 , absolute error: 0.01976695 .
## Iteration n = 2 , approximate root: 1.464977 , absolute error: 0.0003851476 .
## 
## Algorithm converges!
## The approximated root: 1.464592 .
## The absolute error: 1.020909e-07 .
## The number of iterations n = 3 .

Problem 2 1. taylor series expanded at 7.75 Taylor series approximation of the laguerre polynomial f(x)= ((x4)/24)+(2/3)(x3)+(3x^2)-4x+1 f’(x)= ((x3)/6)+2x2+6x-4
f’‘(x)= ((x^2)/2)+4x+6)
f’’‘(x)= (x+4)
f’’’’(x)= 1
Taylor Series Expansion 610.823+240.206(x-7.75)+33.516(x-7.75)2+(1.958)(x-7.75)3+0.041667(x-7.75)^4 Now plug in x=3 which gets 37.418. True value is 1.375 so this is bad approximation

Divided.Dif = function(
        vec.x,          # input nodes:
        vec.y = NULL,   # one of vec.y and fn must be given
        fn = NULL,
        pred.x          # scalar x for predicting pn(pred.x)
         ){
   n = length(vec.x)
   if (length(vec.y) == 0) vec.y = fn(vec.x) #
   node.x = vec.x
   A = matrix(c(rep(0,n^2)), nrow = n, ncol = n, byrow = TRUE)
   A[1,] = vec.y     # fill the first row with vec.y
   #
   for(i in 2:(n)){
     for(j in 1:(n-i+1)){
      denominator = vec.x[j] - vec.x[j+1+(i-2)]
      numerator = A[i-1,j]- A[i-1,j+1]
      A[i,j] = numerator/denominator
      }
    }
  A
 }
library(pander)
## Warning: package 'pander' was built under R version 4.2.3
pander(Divided.Dif(
        vec.x = c(0.3, 0.95, 3.3, 7.75, 9.4),           
        vec.y = c(0.0523, -0.6301, 1.453, -9.823, 0.069),    
        fn = NULL
        )
     )
0.0523 -0.6301 1.453 -9.823 0.069
Newton Int 3. erpolated Polynomia l is 0.52 3-1.05(x-.3)+0.6454(x-.3)(x-.95)-.1542(x-.3)(x-.95)(x-3.3)+0.4166(x-.3)(x-.95)(x-3.3)(x-7.75) and now plug in x=3 which gets 4.802 and true value is 1.375. This is better approximation than taylor series
r Divided.Di ve ve fn pr ) n = len if (len node.x A = mat A[1,] = # for(i i for(j deno nume A[i, } } A } f = functi c.x, c.y = NULL = NULL, ed.x { gth(vec.x) gth(vec.y) = vec.x rix(c(rep( vec.y on( # inp , # one
r library(pa pander(Div ve ve fn ) ) nder) ided.Dif( c.x = c(1, c.y = c(-. = NULL

-0.625 1.375 -1.292 -8.625 -4.625

 1       -1.333    -3.667     2        0    

-0.5834 -0.5833 1.417 0 0

2.083e-05 0.3333 0 0 0

0.04166 0 0 0 0
-.625+1(x-1) -0.5834(x- 1)(x-3)+0 .04166 is the Newton Interpolation Polynomial and when we plug in x = 3 we get 1.4167 which is the closest to the true value of 1.375 The newton interpolation polynomial using equally spaced nodes gives the best approximation
Problem 3
Divided.Dif = function(
        vec.x,          # input nodes:
        vec.y = NULL,   # one of vec.y and fn must be given
        fn = NULL,
        pred.x          # scalar x for predicting pn(pred.x)
         ){
   n = length(vec.x)
   if (length(vec.y) == 0) vec.y = fn(vec.x) #
   node.x = vec.x
   A = matrix(c(rep(0,n^2)), nrow = n, ncol = n, byrow = TRUE)
   A[1,] = vec.y     # fill the first row with vec.y
   #
   for(i in 2:(n)){
     for(j in 1:(n-i+1)){
      denominator = vec.x[j] - vec.x[j+1+(i-2)]
      numerator = A[i-1,j]- A[i-1,j+1]
      A[i,j] = numerator/denominator
      }
    }
  A
 }
library(pander)
pander(Divided.Dif(
        vec.x = c(220, 230, 240, 250, 260, 270, 280, 290),           
        vec.y = c(17.19, 20.78, 24.97, 29.82, 35.42, 41.85, 49.18, 57.53),    
        fn = NULL
        )
     )
17.19 20.78 24.97 29.82 35.42 41.85 49.18 57.53
0.359 0.419 0.485 0.56 0.643 0.733 0.835 0
0.003 0.0033 0.00375 0.00415 0.0045 0.0051 0 0
1e-05 1.5e-05 1.333e-05 1.167e-05 2e-05 0 0 0
1.25e-07 -4.167e-08 -4.167e-08 2.083e-07 0 0 0 0
-3.333e-09 -2.197e-23 5e-09 0 0 0 0 0
5.556e-11 8.333e-11 0 0 0 0 0 0
3.968e-13 0 0 0 0 0 0 0

17.19+.359(t-220)+.003(t-220)(t-230) is the polynomial and now plug in the t values

t(235)=22.8 t(255)=32.38 t(279)=47.044 t(295)=58.74