Geng 4
Geng 4
Q1)
a)
The first two iterations using the golden section ratio for the equation
f(t) = 30*t.^4 - 20*t.^3 - sqrt(abs(2 - sqrt(1 + 9*t.^3 + 1./(t + 0.15)))) +1
knowing that the root occurs between x = 0 and x = 0.5 are as follows.
Xs Xl Xo Xn f g
b)
We can use the following matlab function to determine the root of the equation
from part a, with an error < 0.0001, and after how many iterations we can find
this root.
while (1)
f = 30*(xo).^4 - 20*(xo).^3 - sqrt(abs(2 - sqrt(1 + 9*(xo).^3 + 1./((xo) +
0.15)))) +1;
g = 30*(xn).^4 - 20*(xn).^3 - sqrt(abs(2 - sqrt(1 + 9*(xn).^3 + 1./((xn) +
0.15)))) +1;
nite = nite + 1;
if f>g;
xs = xn;
d = ((sqrt(5) - 1)/2)*(xl-xs);
xn = xo
xo = xs + d
else g>f;
xl = xo
d = ((sqrt(5) - 1)/2)*(xl-xs);
xo = xn
xn = xl - d
end
end
Xs Xl Xo Xn f g
These results show that even over such a small interval, quite a few iterations
were required to determine the root with such a small amount of error. The first
11 runs of this function showed the biggest difference between the low value of x
chosen and the high value of x chosen, with the low value moving to 0.1894 and
the high value moving to 0.1935, leaving a range of just 0.041. This suggests
that, when using the golden section by hand, a smaller interval should be used
for a more time efficient method, or a larger error should be allowed for.
Q2)
0.2
-0.2
-0.4
-0.6
-0.8
-1
-1.2
1.5 2 2.5 3 3.5 4 4.5 5
Q3)
We are trying to find out the distance a car travels as it decelerates from 50m/s
to 25m/s, using the equation 2000*u(du/dx) = - 10*(u.^2+100).*(1+1./exp((u-30).^2)) to
illustrate the cruising of the car.
a)
Using the trapezoidal rule in matlab, for 16, 32 and 128 iterations, we can
determine the distance travelled by the car.
for n = 1:interval-1
x = x + 1;
u = (50+x*((25-50)/interval)); %the velocity at each interval
A(x) = (2000*u)./(-10.*(u.^2+100).*(1+1./exp((u-30).^2)));
end
end
For 16 iterations, the car travels 121.38 meters with a speed decreasing from
50m/s to 25m/s
For 32 iterations, the car travels 121.28 meters with a speed decreasing from
50m/s to 25m/s
For 128 iterations, the car travels 121.27 meters with a speed decreasing from
50m/s to 25m/s
b)
elseif (runs == 1)
interval = 32; %for the second run, use 32 intervals
runs = 2;
elseif runs == 2
interval = 128; %for the third run, use 128 intervals
end
fa = (2000*50)./(-10.*(50.^2+100).*(1+1./exp((50-30).^2))); %force at 50
km/h
fb = (2000*25)./(-10.*(25.^2+100).*(1+1./exp((25-30).^2))); %force at 25
km/h
x = 0
for n = 1:((interval/2)-1)
x = x + 2;
u = (50+(x-1)*((25-50)/interval));
r = (50+x*((25-50)/interval));
A(x) = (2000*u)./(-10.*(u.^2+100).*(1+1./exp((u-30).^2)));
B(x) = (2000*r)./(-10.*(r.^2+100).*(1+1./exp((r-30).^2)));
end
end
For 16 iterations, the car travels 106.73 meters with a speed decreasing from
50m/s to 25m/s
For 32 iterations, the car travels 114.22 meters with a speed decreasing from
50m/s to 25m/s
For 128 iterations, the car travels 119.49 meters with a speed decreasing from
50m/s to 25m/s
c)
By hand, we evaluate the area under the curve to equal 127.71, meaning that
the car travelled 127.71m as it slowed down from 50m/s to 25m/s.
1020
1000
980
960
940
920
900
880
25 30 35 40 45 50
d) The value generated by hand was quite a bit larger than the values generated
by matlab using the trapezoidal and simpson rules. This makes sense, as the
trapezoidal rule and simpson rule are approximations, and would cut out part of
the curve. It also shows that the trapezoidal rule is generating answers closer to
the real value of the distance, and is more accurate in this case.
Katherine Chapman
20268352