# Problem 13: # pr = polyroot( c( 1.25, 2, 1 ) ) print(pr) # Problem 14: # pr = polyroot( c( -4, 9, 9 ) ) print(pr) # Problem 15: # pr = polyroot( c( 1.25, 1, 1 ) ) print(pr) # Problem 16: # pr = polyroot( c( 6.25, 4, 1 ) ) print(pr) # Problem 18: # pr = polyroot( c( 5, 4, 1 ) ) print(pr) # Problem 19: # pr = polyroot( c( 5, -2, 1 ) ) print(pr) # Problem 20: # A = matrix( c( 1/2, sqrt(3)/2, -sqrt(3)/2, 1/2 ), nrow=2, ncol=2, byrow=T ) b=c( 2, -4) x = solve( A, b ) print(x) # Problem 21: # pr = polyroot( c( 1.25, 1, 1 ) ) print(pr) # Problem 22: # pr = polyroot( c( 2, 2, 1 ) ) print(pr) A = matrix( c( 1/2, sqrt(3)/2, -sqrt(3)/2, 1/2 ), nrow=2, ncol=2, byrow=T ) b=c(2, 4) x = solve( A, b ) print(x) # Problem 23: # pr = polyroot( c( 2, -1, 3 ) ) print(pr) u = function(t){ 2 * exp(t/6) * cos( ( sqrt(23)/6 ) * t ) - (2 / sqrt(23)) * exp(t/6) * sin( ( sqrt(23)/6 ) * t ) } # Looks like the first time |u| = 10 is when 10 < t < 11: # library(stats) res = uniroot( function(t){ u(t) + 10 }, c(10.0, 11.0) ) t = res$root print(sprintf('u(t)=-10 when t= %f', t)) ts = seq(0, 15, length.out=500 ) us = u(ts) #postscript("../../WriteUp/Graphics/Chapter3/chap_3_sect_3_prob_23_plot.eps", onefile=FALSE, horizontal=FALSE) plot(ts, us, type='l', xlab='t', ylab='u(t)') abline(h=c(-10, 10), col='blue') abline(v=t, col='black') grid() #dev.off() # Problem 24: # pr = polyroot( c( 7, 2, 5) ) print(pr) u = function(t){ 2 * exp(-t/5) * cos( ( sqrt(34)/5 ) * t ) + (7/sqrt(34)) * exp(-t/5) * sin( ( sqrt(34)/5 ) *t ) } ts = seq(5, 30, length.out=1000 ) #ts = seq(12.5, 15, length.out=1000 ) us = u(ts) # Looks like |u(t)| < 0.1 for all times with t > T when 14.0 < T < 15.0 # library(stats) res = uniroot( function(t){ u(t) + 0.1 }, c(14.0, 15.0) ) t = res$root print(sprintf('|u(t)|<0.1 for all t > T when T= %f', t)) #postscript("../../WriteUp/Graphics/Chapter3/chap_3_sect_3_prob_24_plot.eps", onefile=FALSE, horizontal=FALSE) plot(ts, us, type='l', xlab='t', ylab='u(t)') abline(h=c(-0.1, 0.1), col='blue') abline(v=t, col='black') grid() #dev.off() # Problem 25: # pr = polyroot( c( 6, 2, 1) ) print(pr) u = function(t, a=1.0){ 2 * exp(-t) * cos( sqrt(5) * t ) + ((a+2)/sqrt(5)) * exp(-t) * sin( sqrt(5) * t ) } alpha = -2 * ( cos(sqrt(5)) / sin(sqrt(5)) ) * sqrt(5) - 2 print(sprintf('alpha= %f', alpha)) ts = seq(0, 5, length.out=1000 ) us = u(ts, a=alpha) #postscript("../../WriteUp/Graphics/Chapter3/chap_3_sect_3_prob_25_part_b_plot.eps", onefile=FALSE, horizontal=FALSE) plot(ts, us, type='l', xlab='t', ylab='u(t)') grid() #dev.off() ts = seq( 0, pi, length.out=1000 ) / sqrt(5) ys = tan( sqrt(5) * ts ) plot( ts, ys, type='l' ) grid() # Problem 26: # y = function(t, a=1){ exp(-a*t) * cos(t) + a * exp(-a*t) * sin(t) } ts = seq(0, 12.5, length.out=1000 ) ys_a_1 = y(ts, a=1.0) ys_a_1_over_4 = y(ts, a=1/4) ys_a_1_over_2 = y(ts, a=1/2) ys_a_2 = y(ts, a=2) y_min = min( c(-0.1, ys_a_1, ys_a_1_over_4, ys_a_1_over_2, ys_a_2) ) y_max = max( c(+0.1, ys_a_1, ys_a_1_over_4, ys_a_1_over_2, ys_a_2) ) #postscript("../../WriteUp/Graphics/Chapter3/chap_3_sect_3_prob_26_part_b_plot.eps", onefile=FALSE, horizontal=FALSE) plot(ts, ys_a_1, type='l', xlab='t', ylab='y(t)', ylim=c(y_min, y_max), col='black') points(ts, ys_a_1_over_4, type='l', col='blue') points(ts, ys_a_1_over_2, type='l', col='green') points(ts, ys_a_2, type='l', col='red') abline(h=c(-0.1, +0.1), col='black') grid() legend( 'topright', c('a=1', 'a=1/4', 'a=1/2', 'a=2'), lwd=2, lty=c(1, 1, 1, 1), col=c('black', 'blue', 'green', 'red') ) #dev.off() # Find the smallest T such that ly(t)|<0.1 for all t > T # library(stats) all_as = c() all_ts = c() a=1.0 res = uniroot( function(t){ y(t, a=a) - 0.1 }, c(1.5, 2.5) ) t = res$root print(sprintf('a= %f: |y(t)|<0.1 for all t > T when T= %f', a, t)) all_as = c( all_as, a ) all_ts = c( all_ts, t ) a=1/4 res = uniroot( function(t){ y(t, a=a) - 0.1 }, c(6, 8) ) t = res$root print(sprintf('a= %f: |y(t)|<0.1 for all t > T when T= %f', a, t)) all_as = c( all_as, a ) all_ts = c( all_ts, t ) a=1/2 res = uniroot( function(t){ y(t, a=a) + 0.1 }, c(3.5, 4.5) ) t = res$root print(sprintf('a= %f: |y(t)|<0.1 for all t > T when T= %f', a, t)) all_as = c( all_as, a ) all_ts = c( all_ts, t ) a=2 res = uniroot( function(t){ y(t, a=a) - 0.1 }, c(1.0, 2.0) ) t = res$root print(sprintf('a= %f: |y(t)|<0.1 for all t > T when T= %f', a, t)) all_as = c( all_as, a ) all_ts = c( all_ts, t ) indxs = sort.list(all_as) all_as = all_as[indxs] all_ts = all_ts[indxs] #postscript("../../WriteUp/Graphics/Chapter3/chap_3_sect_3_prob_26_part_c_plot.eps", onefile= FALSE, horizontal= FALSE) plot( all_as, all_ts, type='l', xlab='a', ylab='T' ) grid() #dev.off() # Problem 36: # pr = polyroot( c( 2, 3, 1 ) ) print(pr) # Problem 37: # pr = polyroot( c( 1.25, 2, 1 ) ) print(pr) # Problem 40: # pr = polyroot( c( 5, -2, 1 ) ) print(pr) # Problem 42: # pr = polyroot( c( 10, 6, 1 ) ) print(pr) # Problem 46: # pr = polyroot( c( 1, 1, 1 ) ) print(pr)