1 function [x, y] = secantsolve(myfun, guess1, guess0, goal, maxerror, C, R1, R2, R3) 2 % [x, y] = secantsolve(myfun, guess1, guess0, goal, maxerror, C, R1, R2, R3) 3 % secant solver equation 4 % xj = xi - (xi-xh)/(yi-yh)*yi 5 6 xj = guess1; 7 xi = guess0; 8 yj = myfun(guess1, C, R1, R2, R3); 9 10 while abs(yj - goal) > maxerror && xi > 0 11 12 % shift x values 13 xh = xi; 14 xi = xj; 15 % evaluate at x values 16 yi = yj - goal; 17 yh = myfun(xh, C, R1, R2, R3) - goal; 18 % iterate 19 xj = xi - (xi-xh)/(yi-yh)*yi 20 yj = myfun(xj, C, R1, R2, R3) 21 22 end 23 24 x = xj; 25 y = yj;