Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Solution:
x=linspace (0,6)
y=x.^3-10*x.^2+29.*x-20
plot(x,y)
grid on
axis([0 6 -10 10])
%roots x1=1.0 x2=4.0 and x3=5.0
10
-2
-4
-6
-8
-10
0 1 2 3 4 5 6
2. The volume of the liquid in a hollow horizontal cylinder of radius r an length L is related
to the depth of the liquid h by the following formula:
r h 2
V r 2 arccos (r h) 2rh h L
r
1
grid on
60
50
40
30
20
10
-10
0 0.5 1 1.5 2 2.5 3 3.5 4
function y=func(x)
r=2;
L=5;
V=8;
y=(r^2.*acos((r-x)./r).*L-(r-x).*sqrt(2*r.*x-x.^2).*L)-V;
% bisection method
clear,clc
xl=input('ml=')
xr=input('mr=')
eps0=2e-6
if (func(xl)*func(xr))<=0
while abs((xr-xl)/xl)>eps0
x=0.5*(xr+xl);
if (func(x)*func(xr))<=0
xl=x;
else
xr=x;
end
end
disp('root=');disp(xr);
else
disp('Incorrect initial guesses!')
end
3. The trajectory of a baseball thrown by a right fielder is defined by the (x, y) coordinates
as displayed in Figure. The trajectory can be modeled as
2
( )
( )
Find the two possible initial angles 0 in the interval [0, pi/2.5], if v0 = 20 m/s, and the
distance to the catcher is x=30 m. Note that the throw leaves the right fielder's hand at an
elevation of y0=2 m and the catcher receives it at y = 2 m. Use graphical method to
estimate the brackets for each of the roots and use the Bisection method to obtain the
accurate values of the angles.
Solution:
Estimate the brackets for each of the two roots from the graph
theta=linspace(0,pi/2.5);
x=30;v0=20;y0=2;y=2;g=9.81;
f=x*tan(theta)-g*x^2./(2*v0^2*(cos(theta)).^2)+y0-y;
plot(theta,f)
grid on
3
10
-5
-10
-15
-20
-25
0 0.2 0.4 0.6 0.8 1 1.2 1.4
root2: xl=1,xr=1.2
With these brackets, the angles are 0.4134 (23.7°) and 1.1574 (66.3°)
xl=input('ml=')
xr=input('mr=')
eps0=2e-6
if (func1(xl)*func1(xr))<=0
while abs((xr-xl)/xl)>eps0
x=0.5*(xr+xl);
if (func1(x)*func1(xr))<=0
xl=x;
else
xr=x;
end
end
disp('root=');disp(xr);
else
end
4
where
function f=func1(theta)
x=30;v0=20;y0=2;y=2;g=9.81;
f=x*tan(theta)-g*x^2./(2*v0^2*(cos(theta)).^2)+y0-y;
5
Section 52
85-220 Numerical Analysis of Engineering Systems
Winter 2014
Tutorial 2
1. For the range of 0 <= x <= 7 graphically estimate the roots of
( )
Solution:
x=linspace(0,7)
y=1.4*x.^3-12*x.^2+22.*x-5
plot(x,y)
grid on
50
40
30
20
10
-10
-20
-30
0 1 2 3 4 5 6 7
2. The volume of the liquid in a hollow horizontal cylinder of radius r an length L is related
to the depth of the liquid h by the following formula:
r h 2
V r 2 arccos (r h) 2rh h L
r
Solution:
6
%problem 2
% function y=func(x)
x=linspace(0, 4)
r=2;
L=2;
V=15;
y=(r^2.*acos((r-x)./r).*L-(r-x).*sqrt(2*r.*x-x.^2).*L)-V;
plot(x,y)
grid on
15
10
-5
-10
-15
0 0.5 1 1.5 2 2.5 3 3.5 4
function y=func(x)
r=2;
L=2;
V=15;
y=(r^2.*acos((r-x)./r).*L-(r-x).*sqrt(2*r.*x-x.^2).*L)-V;
Bisection method
xl=input('ml=')
xr=input('mr=')
eps0=2e-6
if (func(xl)*func(xr))<=0
while abs((xr-xl)/xl)>eps0
x=0.5*(xr+xl);
if (func(x)*func(xr))<=0
xl=x;
else
xr=x;
end
end
disp('root=');disp(xr);
else
disp('Incorrect initial guesses!')
end
%root= 2.3054
7
3. The trajectory of a baseball thrown by a right fielder is defined by the (x, y) coordinates
as displayed in Figure. The trajectory can be modeled as
( )
( )
Find the two possible initial angles 0 in the interval [0, pi/2.5], if v0 = 20 m/s, and the
distance to the catcher is x=35 m. Note that the throw leaves the right fielder's hand at an
elevation of y0=2 m and the catcher receives it at y=1 m. Use graphical method to
estimate the brackets for each of the roots and use the Bisection method to obtain the
accurate values of the angles.
Solution:
Estimate the brackets for each of the two roots from the graph
clear,clc
theta=linspace(0,pi/2.5);
x=35;v0=20;y0=2;y=1;g=9.81;
f=x*tan(theta)-g*x^2./(2*v0^2*(cos(theta)).^2)+y0-y;
plot(theta,f)
grid on
8
10
-10
-20
-30
-40
-50
0 0.2 0.4 0.6 0.8 1 1.2 1.4
xl=input('ml=')
xr=input('mr=')
eps0=2e-6
if (func(xl)*func(xr))<=0
while abs((xr-xl)/xl)>eps0
x=0.5*(xr+xl);
if (func(x)*func(xr))<=0
xl=x;
else
xr=x;
end
end
disp('root=');disp(xr);
else
disp('Incorrect initial guesses!')
end
where
function ft=func(theta)
g=9.81;%m/s2
x=35; %m
y0=2;%m
y=1;%m
v0=20.0;%m/s
ft=x*tan(theta)-g*x^2./(2*v0^2*(cos(theta)).^2)+y0-y;
9
Section 53
85-220 Numerical Analysis of Engineering Systems
Winter 2014
Tutorial 2
4. For the range of 0 <= x <= 6 graphically estimate the roots of
( ) .
Solution:
x=linspace (0,6)
y=x.^3-10*x.^2+29.*x-20
plot(x,y)
grid on
axis([0 6 -10 10])
%roots x1=1.0 x2=4.0 and x3=5.0
10
-2
-4
-6
-8
-10
0 1 2 3 4 5 6
5. The volume of the liquid in a hollow horizontal cylinder of radius r an length L is related
to the depth of the liquid h by the following formula:
r h 2
V r 2 arccos (r h) 2rh h L
r
10
grid on
60
50
40
30
20
10
-10
0 0.5 1 1.5 2 2.5 3 3.5 4
function y=func(x)
r=2;
L=5;
V=8;
y=(r^2.*acos((r-x)./r).*L-(r-x).*sqrt(2*r.*x-x.^2).*L)-V;
% bisection method
clear,clc
xl=input('ml=')
xr=input('mr=')
eps0=2e-6
if (func(xl)*func(xr))<=0
while abs((xr-xl)/xl)>eps0
x=0.5*(xr+xl);
if (func(x)*func(xr))<=0
xl=x;
else
xr=x;
end
end
disp('root=');disp(xr);
else
disp('Incorrect initial guesses!')
end
6. The trajectory of a baseball thrown by a right fielder is defined by the (x, y) coordinates
as displayed in Figure. The trajectory can be modeled as
11
( )
( )
Find the two possible initial angles 0 in the interval [0, pi/2.5], if v0 = 20 m/s, and the
distance to the catcher is x=30 m. Note that the throw leaves the right fielder's hand at an
elevation of y0=2 m and the catcher receives it at y = 2 m. Use graphical method to
estimate the brackets for each of the roots and use the Bisection method to obtain the
accurate values of the angles.
Solution:
Estimate the brackets for each of the two roots from the graph
theta=linspace(0,pi/2.5);
x=30;v0=20;y0=2;y=2;g=9.81;
f=x*tan(theta)-g*x^2./(2*v0^2*(cos(theta)).^2)+y0-y;
plot(theta,f)
grid on
12
10
-5
-10
-15
-20
-25
0 0.2 0.4 0.6 0.8 1 1.2 1.4
root2: xl=1,xr=1.2
With these brackets, the angles are 0.4134 (23.7°) and 1.1574 (66.3°)
xl=input('ml=')
xr=input('mr=')
eps0=2e-6
if (func1(xl)*func1(xr))<=0
while abs((xr-xl)/xl)>eps0
x=0.5*(xr+xl);
if (func1(x)*func1(xr))<=0
xl=x;
else
xr=x;
end
end
disp('root=');disp(xr);
else
end
13
where
function f=func1(theta)
x=30;v0=20;y0=2;y=2;g=9.81;
f=x*tan(theta)-g*x^2./(2*v0^2*(cos(theta)).^2)+y0-y;
14
Section 54
85-220 Numerical Analysis of Engineering Systems
Winter 2014
Tutorial 2
4. For the range of 0 <= x <= 7 graphically estimate the roots of
( )
Solution:
x=linspace(0,7)
y=1.4*x.^3-12*x.^2+22.*x-5
plot(x,y)
grid on
50
40
30
20
10
-10
-20
-30
0 1 2 3 4 5 6 7
5. The volume of the liquid in a hollow horizontal cylinder of radius r an length L is related
to the depth of the liquid h by the following formula:
r h 2
V r 2 arccos (r h) 2rh h L
r
Solution:
15
%problem 2
% function y=func(x)
x=linspace(0, 4)
r=2;
L=2;
V=15;
y=(r^2.*acos((r-x)./r).*L-(r-x).*sqrt(2*r.*x-x.^2).*L)-V;
plot(x,y)
grid on
15
10
-5
-10
-15
0 0.5 1 1.5 2 2.5 3 3.5 4
function y=func(x)
r=2;
L=2;
V=15;
y=(r^2.*acos((r-x)./r).*L-(r-x).*sqrt(2*r.*x-x.^2).*L)-V;
Bisection method
xl=input('ml=')
xr=input('mr=')
eps0=2e-6
if (func(xl)*func(xr))<=0
while abs((xr-xl)/xl)>eps0
x=0.5*(xr+xl);
if (func(x)*func(xr))<=0
xl=x;
else
xr=x;
end
end
disp('root=');disp(xr);
else
disp('Incorrect initial guesses!')
end
%root= 2.3054
16
6. The trajectory of a baseball thrown by a right fielder is defined by the (x, y) coordinates
as displayed in Figure. The trajectory can be modeled as
( )
( )
Find the two possible initial angles 0 in the interval [0, pi/2.5], if v0 = 20 m/s, and the
distance to the catcher is x=35 m. Note that the throw leaves the right fielder's hand at an
elevation of y0=2 m and the catcher receives it at y=1 m. Use graphical method to
estimate the brackets for each of the roots and use the Bisection method to obtain the
accurate values of the angles.
Solution:
Estimate the brackets for each of the two roots from the graph
clear,clc
theta=linspace(0,pi/2.5);
x=35;v0=20;y0=2;y=1;g=9.81;
f=x*tan(theta)-g*x^2./(2*v0^2*(cos(theta)).^2)+y0-y;
plot(theta,f)
grid on
17
10
-10
-20
-30
-40
-50
0 0.2 0.4 0.6 0.8 1 1.2 1.4
xl=input('ml=')
xr=input('mr=')
eps0=2e-6
if (func(xl)*func(xr))<=0
while abs((xr-xl)/xl)>eps0
x=0.5*(xr+xl);
if (func(x)*func(xr))<=0
xl=x;
else
xr=x;
end
end
disp('root=');disp(xr);
else
disp('Incorrect initial guesses!')
end
where
function ft=func(theta)
g=9.81;%m/s2
x=35; %m
y0=2;%m
y=1;%m
v0=20.0;%m/s
ft=x*tan(theta)-g*x^2./(2*v0^2*(cos(theta)).^2)+y0-y;
18