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.')
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')
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
r = 6.4e6; v = 5e3; f = v*c/r; T = 1/f
ezplot(hx, [0, 10]) hold on; plot(c,0,'r.') plot(c,0,'ro')
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
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)
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])