Secant Method not Working, Please Help!
Show older comments
my code isnt working , i need help fixing my secant method so that it updates every guess with every iteration. i need the guess 1 to update to guess 2 from the last iteration and i need guess 2 to update to the root found from the secant method. i need to find a root for each of the f in a range of 1 to 750. Any help is appreciated, this project is due tommorow.
%% parameters
% Aluminum plate E = 69GPa, v = 0.3269, p = 2700 kg/m^3
% Copper E = 117 GPa, v = 0.34, p= 8920 g/cm^3
E = 69e9;
p = 2700;
v = .3269;
c1 = sqrt((E*(1-v)) / (p*(1+v)*(1-2*v))); % Pwave (m/s)
c2 = sqrt(E / (2*p*(1+v))); % S wave (m/s)
f = 1e3:1e3:750e3; % 1 to 750 khz (we can choose step size)(frequency)
n = length(f);
k = 1:1:2000; %range of wavenumbers
for j =1:n
w(j)= 2*pi*f(j); % angular frequency
H = (3.175e-3) / 2; % m (plate thickness)
k1(j) = w(j)/c1; % wavenumber
k2(j) = w(j)/c2;
for i = 1:length(k)
n_1(j) = sqrt((i)^2-k1(j)^2);
n_2(j) = sqrt((i)^2 - k2(j)^2);
f1(i,j) = (((2* (i)^2 - (k2(j))^2)^2)*(sinh(n_1(j)*H)*cosh(n_2(j) *H))-(4*(i)^2 * n_1(j) * n_2(j)*cosh(n_1(j)*H)*sinh(n_2(j) *H))); %function
% f2(i) = (((2* i^2 - (k2(j))^2)^2)*(cosh(n_1*H)*sinh(n_2 *H))-(4*i^2 * n_1 * n_2*sinh(n_1*H)*cosh(n_2 *H)));
end
end
%% Root finding methods (Secant method)
% f1 antisymmetric function kg is the root
kg1 = 21;
kg2 = 50;
eps = 0.1;
for j = 1:750
i = 2;
while abs(f1) > eps
i = i + 1;
kg(i) = kg(i-1) - (f1(kg(i-1))*(kg(i-1) - kg(i-2))) / (f1(kg(i-1))-f1(kg(i-2)));
end
root1 = kg(end);
if i > 2
kg(2) = kg(1);
kg(end) = kg(2);
end
end
Answers (0)
Categories
Find more on Pole and Zero Locations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!