2024-03-06

theme_rbook = function(base_size = 13, base_family="", base_line_size = base_size / 22, base_rect_size = base_size / 22) {
  theme(
    axis.title = element_text(size = 13),
    axis.text.x = element_text(size = 10),
    axis.text.y = element_text(size = 10),
    plot.caption = element_text(size = 20, face = "italic"),
    plot.title = element_text(size = 18, face = "italic"),
    panel.background = element_rect(fill = "white"),
    axis.line = element_line(size = 1, color = "black"),
    strip.background = element_rect(fill = "#cddcdd"),
    panel.border = element_rect(color = "black", fill = NA, size = 0.05),
    strip.text = element_text(color = "black"),
    legend.key = element_blank()
  )}
readeuler <- read.csv("EulerFun.csv")
euler <- readeuler[, 1:5]
str(euler)
## 'data.frame':    9999 obs. of  5 variables:
##  $ x        : num  0 0.001 0.001 0.002 0.002 0.003 0.003 0.004 0.004 0.005 ...
##  $ y        : num  0 0.003 0.006 0.009 0.012 0.015 0.018 0.021 0.024 0.027 ...
##  $ dy.dx    : num  6 5.99 5.98 5.96 5.95 ...
##  $ d.2y.dx.2: num  -23.7 -23.6 -23.5 -23.5 -23.4 ...
##  $ Solution : num  0 0.003 0.006 0.009 0.012 0.015 0.018 0.021 0.024 0.027 ...
head(euler)
##       x     y dy.dx d.2y.dx.2 Solution
## 1 0.000 0.000 6.000   -23.667    0.000
## 2 0.001 0.003 5.988   -23.607    0.003
## 3 0.001 0.006 5.976   -23.548    0.006
## 4 0.002 0.009 5.965   -23.489    0.009
## 5 0.002 0.012 5.953   -23.430    0.012
## 6 0.003 0.015 5.941   -23.371    0.015
tail(euler)
##          x      y  dy.dx d.2y.dx.2 Solution
## 9994 4.996 70.881 58.789    48.702   62.924
## 9995 4.997 70.911 58.813    48.722   62.945
## 9996 4.997 70.940 58.838    48.743   62.966
## 9997 4.998 70.969 58.862    48.763   62.987
## 9998 4.998 70.999 58.886    48.783   63.008
## 9999 4.999 71.028 58.911    48.803   63.029

Euler Example

This image demonstrates what Euler's method does, it is a numerical approximation of an analytical solution. It is an incredibly useful tool, which we will see demonstrated in this presentation, for cases where data must be quickly approximated as a smooth curve rather than a discontinuous set of data points.

This image demonstrates what Euler’s method does, it is a numerical approximation of an analytical solution. It is an incredibly useful tool, which we will see demonstrated in this presentation, for cases where data must be quickly approximated as a smooth curve rather than a discontinuous set of data points.

Calculated Graph with ggplot

ggplot(aes(x = x, y = y), data = euler) +
  geom_point(aes(color = "blue"), size = 0.1, alpha = 1) + 
  
  xlab("Input x Values") + 
  ylab("Calculated y Values") + 
  geom_hline(aes(yintercept = mean(y)), size = 0.5, color = "red", linetype = 4) +
  
  labs(shape = "Calculated", color = "Calculated", 
       caption = "*This is a plot of calculated values", title = "Calculated Figure") + 
  
  theme_rbook()
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## Warning: The `size` argument of `element_line()` is deprecated as of ggplot2 3.4.0.
## ℹ Please use the `linewidth` argument instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## Warning: The `size` argument of `element_rect()` is deprecated as of ggplot2 3.4.0.
## ℹ Please use the `linewidth` argument instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.

Analytical Graph with ggplot

ggplot(aes(x = x, y = Solution), data = euler) +
  geom_point(size = 0.1, alpha = 1) + 
  
  xlab("Input x Values") + 
  ylab("Exact y Values") + 
  geom_hline(aes(yintercept = mean(Solution)), size = 0.5, color = "red", linetype = 4) +
  
  labs(shape = "Exact", color = "Exact", 
       caption = "*This is a plot of exact values", title = "Analytical Figure") + 
  
  scale_y_continuous()+
  scale_color_gradientn(colors = c("#1252ED", "#12ED3F", "#EDAD12", "#ED12C0"),
                        values = c(0, 0.25, 0.5, 0.75, 1)) +
  
  theme_rbook()

3D Plot of Solutions

readeuler <- read.csv("EulerFun.csv")
euler <- readeuler[, 1:5]

X = euler$Solution
Y = euler$y
Z = euler$x
fig <- plot_ly(x=X, y=Y, z=Z,
        type="scatter3d", mode="markers", color = Z)

fig <- fig %>% layout(list(
  scene = list(camera = list(eye = list(x = 100, y = 50, z = 10)))
))
fig <- fig %>% layout(
  scene = list(
    xaxis = list(range = c(0, 100)),
    yaxis = list(range = c(0, 100)),
    zaxis = list(range = c(0, 5))
  )
)

fig

Finding General Solution

\[ Differential\:Equation: 3y'' + 4y' - 4y = 0 \\ \:\\ Characteristic\:Equation: 3r^2 + 4r - 4 = 0 \\ \:\\ Roots: r =\:-2,\:\frac{2}{3} \\ \:\\ Case: Real\:and\:Unique\:Roots \\ \:\\ General\:Solution:\: C_1e^{-2x}\:+\:C_2e^{2/3x} \]

Finding Specific Solution

\[ General\:Solution:\: C_1e^{-2x}\:+\:C_2e^{2/3x} \\ \:\\ Initial\:Conditions:\: y(0)=0,\; y'(0)=6 \\ \:\\ 0=C_1+C_2,\:\:C_1=-C_2 \:\\ 6 = -2C_1+\frac{2}{3}C_2 \:\\ 6 = 2C_2+\frac{2}{3}C_2 \:\\ C_1 = -\frac{9}{4},\:\:C_2 = \frac{9}{4}\\ \:\\ Specific\:Solution: y(x) =-\frac{9}{4}e^{-2x}\:+\:\frac{9}{4}e^{2/3x} \]

Euler Engine Excel File

A caption

A caption