Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

cosc_lab_tues_w6

Project: cosc
Views: 169
Kernel: Octave

Q1

ezplot('tan(x)',[0,10]) hold on; g = @(x) 4*x./(4-x.^2); lb = 3*pi/2+0.1; ub = 5*pi/2-0.1; hold on; ezplot(g, [0,10]) plot([lb,ub],[0,0], 'ro') plot([lb,ub],[0,0], 'r.')
Image in a Jupyter notebook
format long % Solve (4-x.*x)*tan(x) - 4x = 0 % tan(x) disc at each (2n+1)(pi/2) % Guess lower, upper bracket = 3pi/2+0.1, 5pi/2 -0.1 hx = @(x) (4-x.^2).*tan(x)-4*x; ezplot(hx, [0, 10]) hold on; plot([lb,ub],[0,0], 'r.') plot([lb,ub],[0,0], 'ro')
Image in a Jupyter notebook
hx = @(x) (4-x.^2).*tan(x)-4*x; TOL = 1e-7; a = 3*pi/2+0.1; b = 5*pi/2-0.1; for n = 1:100 c = (a+b)/2 if abs((b-a)/2) <= TOL disp(n) break elseif sign(hx(c)) == sign(hx(a)) a = c; else b = c; end end
c = 6.28318530717959 c = 5.54778714378214 c = 5.91548622548086 c = 5.73163668463150 c = 5.63971191420682 c = 5.59374952899448 c = 5.61673072160065 c = 5.60524012529756 c = 5.59949482714602 c = 5.59662217807025 c = 5.59805850260814 c = 5.59734034033919 c = 5.59698125920472 c = 5.59680171863749 c = 5.59671194835387 c = 5.59675683349568 c = 5.59677927606658 c = 5.59676805478113 c = 5.59677366542386 c = 5.59677086010249 c = 5.59677226276317 c = 5.59677156143283 c = 5.59677191209800 c = 5.59677208743059 c = 5.59677217509688 25
r = 6.4e6; v = 5e3; f = v*c/r; T = 1/f
T = 228.703252509621
ezplot(hx, [0, 10]) hold on; plot(c,0,'r.') plot(c,0,'ro')
Image in a Jupyter notebook

Q2

format longE;
function [x] = newt(x0,n) f = @(y) y^2 -3; df = @(y) 2*y; if n == 0 x = x0; else temp = newt(x0,n-1); x = temp - f(temp)/df(temp); end end
TOL = 1e-10; err = TOL + 1; n = 0; while err > TOL n += 1 err = newt(2,n) - sqrt(3) end
n = 1.00000000000000E+00 err = 1.79491924311228E-02 n = 2.00000000000000E+00 err = 9.20495739800131E-05 n = 3.00000000000000E+00 err = 2.44585041109247E-09 n = 4.00000000000000E+00 err = 0.00000000000000E+00

Q3

u = 16; g = 9.8; time = @(th) 20/(u*cosd(th)); y = @(th) u*time(th)*sind(th)-(g/2)*time(th)^2 -4; th1 = fzero(y, 55) th2 = fzero(y, 50)
th1 = 6.00350373511171E+01 th2 = 4.12748951229031E+01
th = th1; t = time(th); min(norm([u*t*cosd(th), u*t*sind(th)- (g/2)*t.^2])-[20,4]) th = th2; t = time(th); min(norm([u*t*cosd(th), u*t*sind(th)- (g/2)*t.^2])-[20,4])
ans = 3.96078054371142E-01 ans = 3.96078054371142E-01