R Markdown
# Calculate the first 50 power values of 2
powers_of_2 <- 2^(1:50)
show(powers_of_2)
## [1] 2.000000e+00 4.000000e+00 8.000000e+00 1.600000e+01 3.200000e+01
## [6] 6.400000e+01 1.280000e+02 2.560000e+02 5.120000e+02 1.024000e+03
## [11] 2.048000e+03 4.096000e+03 8.192000e+03 1.638400e+04 3.276800e+04
## [16] 6.553600e+04 1.310720e+05 2.621440e+05 5.242880e+05 1.048576e+06
## [21] 2.097152e+06 4.194304e+06 8.388608e+06 1.677722e+07 3.355443e+07
## [26] 6.710886e+07 1.342177e+08 2.684355e+08 5.368709e+08 1.073742e+09
## [31] 2.147484e+09 4.294967e+09 8.589935e+09 1.717987e+10 3.435974e+10
## [36] 6.871948e+10 1.374390e+11 2.748779e+11 5.497558e+11 1.099512e+12
## [41] 2.199023e+12 4.398047e+12 8.796093e+12 1.759219e+13 3.518437e+13
## [46] 7.036874e+13 1.407375e+14 2.814750e+14 5.629500e+14 1.125900e+15
# Calculate the squares of all integer numbers from 1 to 50
squares <- (1:50)^2
show(squares)
## [1] 1 4 9 16 25 36 49 64 81 100 121 144 169 196 225
## [16] 256 289 324 361 400 441 484 529 576 625 676 729 784 841 900
## [31] 961 1024 1089 1156 1225 1296 1369 1444 1521 1600 1681 1764 1849 1936 2025
## [46] 2116 2209 2304 2401 2500
# Find pairs where 2^n = n^2
matching_pairs <- which(powers_of_2 == squares)
show(matching_pairs)
## [1] 2 4
# Create a sequence of numbers from 0 to 2π with a step of 0.1
x <- seq(0, 2 * pi, by = 0.1)
show(x)
## [1] 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8
## [20] 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7
## [39] 3.8 3.9 4.0 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9 5.0 5.1 5.2 5.3 5.4 5.5 5.6
## [58] 5.7 5.8 5.9 6.0 6.1 6.2
# Calculate sine, cosine, and tangent using sin(), cos(), and tan() functions
sine <- sin(x)
cosine <- cos(x)
tangent_sin_cos <- sin(x) / cos(x)
show(sine)
## [1] 0.00000000 0.09983342 0.19866933 0.29552021 0.38941834 0.47942554
## [7] 0.56464247 0.64421769 0.71735609 0.78332691 0.84147098 0.89120736
## [13] 0.93203909 0.96355819 0.98544973 0.99749499 0.99957360 0.99166481
## [19] 0.97384763 0.94630009 0.90929743 0.86320937 0.80849640 0.74570521
## [25] 0.67546318 0.59847214 0.51550137 0.42737988 0.33498815 0.23924933
## [31] 0.14112001 0.04158066 -0.05837414 -0.15774569 -0.25554110 -0.35078323
## [37] -0.44252044 -0.52983614 -0.61185789 -0.68776616 -0.75680250 -0.81827711
## [43] -0.87157577 -0.91616594 -0.95160207 -0.97753012 -0.99369100 -0.99992326
## [49] -0.99616461 -0.98245261 -0.95892427 -0.92581468 -0.88345466 -0.83226744
## [55] -0.77276449 -0.70554033 -0.63126664 -0.55068554 -0.46460218 -0.37387666
## [61] -0.27941550 -0.18216250 -0.08308940
## [1] 1.00000000 0.99500417 0.98006658 0.95533649 0.92106099 0.87758256
## [7] 0.82533561 0.76484219 0.69670671 0.62160997 0.54030231 0.45359612
## [13] 0.36235775 0.26749883 0.16996714 0.07073720 -0.02919952 -0.12884449
## [19] -0.22720209 -0.32328957 -0.41614684 -0.50484610 -0.58850112 -0.66627602
## [25] -0.73739372 -0.80114362 -0.85688875 -0.90407214 -0.94222234 -0.97095817
## [31] -0.98999250 -0.99913515 -0.99829478 -0.98747977 -0.96679819 -0.93645669
## [37] -0.89675842 -0.84810003 -0.79096771 -0.72593230 -0.65364362 -0.57482395
## [43] -0.49026082 -0.40079917 -0.30733287 -0.21079580 -0.11215253 -0.01238866
## [49] 0.08749898 0.18651237 0.28366219 0.37797774 0.46851667 0.55437434
## [55] 0.63469288 0.70866977 0.77556588 0.83471278 0.88551952 0.92747843
## [61] 0.96017029 0.98326844 0.99654210
## [1] 0.00000000 0.10033467 0.20271004 0.30933625 0.42279322
## [6] 0.54630249 0.68413681 0.84228838 1.02963856 1.26015822
## [11] 1.55740772 1.96475966 2.57215162 3.60210245 5.79788372
## [16] 14.10141995 -34.23253274 -7.69660214 -4.28626167 -2.92709751
## [21] -2.18503986 -1.70984654 -1.37382306 -1.11921364 -0.91601429
## [26] -0.74702230 -0.60159661 -0.47272763 -0.35552983 -0.24640539
## [31] -0.14254654 -0.04161665 0.05847385 0.15974575 0.26431690
## [36] 0.37458564 0.49346673 0.62473308 0.77355609 0.94742465
## [41] 1.15782128 1.42352648 1.77777977 2.28584788 3.09632378
## [46] 4.63733205 8.86017490 80.71276297 -11.38487065 -5.26749307
## [51] -3.38051501 -2.44938942 -1.88564188 -1.50127340 -1.21754082
## [56] -0.99558405 -0.81394328 -0.65973057 -0.52466622 -0.40311090
## [61] -0.29100619 -0.18526223 -0.08337771
# Calculate tangent using the equation tan(x) = sin(x) / cos(x)
tangent_eq <- tan(x)
show(tangent_eq)
## [1] 0.00000000 0.10033467 0.20271004 0.30933625 0.42279322
## [6] 0.54630249 0.68413681 0.84228838 1.02963856 1.26015822
## [11] 1.55740772 1.96475966 2.57215162 3.60210245 5.79788372
## [16] 14.10141995 -34.23253274 -7.69660214 -4.28626167 -2.92709751
## [21] -2.18503986 -1.70984654 -1.37382306 -1.11921364 -0.91601429
## [26] -0.74702230 -0.60159661 -0.47272763 -0.35552983 -0.24640539
## [31] -0.14254654 -0.04161665 0.05847385 0.15974575 0.26431690
## [36] 0.37458564 0.49346673 0.62473308 0.77355609 0.94742465
## [41] 1.15782128 1.42352648 1.77777977 2.28584788 3.09632378
## [46] 4.63733205 8.86017490 80.71276297 -11.38487065 -5.26749307
## [51] -3.38051501 -2.44938942 -1.88564188 -1.50127340 -1.21754082
## [56] -0.99558405 -0.81394328 -0.65973057 -0.52466622 -0.40311090
## [61] -0.29100619 -0.18526223 -0.08337771
# Compare the results
equal_count <- sum(round(tangent_sin_cos, 10) == round(tangent_eq, 10))
max_difference <- max(abs(tangent_sin_cos - tangent_eq))
show(equal_count)
## [1] 63
## [1] 1.421085e-14
# Print the results
cat("Number of equal values:", equal_count, "\n")
## Number of equal values: 63
cat("Largest difference between both calculations:", max_difference, "\n")
## Largest difference between both calculations: 1.421085e-14
## function (..., file = "", sep = " ", fill = FALSE, labels = NULL,
## append = FALSE)
## {
## if (is.character(file))
## if (file == "")
## file <- stdout()
## else if (startsWith(file, "|")) {
## file <- pipe(substring(file, 2L), "w")
## on.exit(close(file))
## }
## else {
## file <- file(file, ifelse(append, "a", "w"))
## on.exit(close(file))
## }
## .Internal(cat(list(...), file, sep, fill, labels, append))
## }
## <bytecode: 0x000001f5d5c470c8>
## <environment: namespace:base>