V = pi * h .^2 *(3*r - h) ./3
Determine h given r = 1 m and V= .5m^3.
Matlab code:
h = -30:30;
r = 1;
V = .5; % m .^3
f = @(h) (pi .* h .^2 .*(3*r - h) ./ 3) - V;
hold on
plot(h , f(h))
h = .43;
delta = .0001;
%Modified secant method
for i = 1:40
h_new = h - (delta * h * f(h)) ./ (f(h + delta*h) - f(h));
h = h_new;
plot(h,h, 'r*')
end
hold off
This produces
The modified secant method was used to pinpoint the solution at .4311
No comments:
Post a Comment