How to apply looping in iteration process ?
1 view (last 30 days)
I required to apply diffrent initail guess for iterative solutions. For a single solution, the following script works perfectly.
L = readmatrix('R_bounds_0.01.csv'); (coloumn matrix with 1986 rows)
f = @(n)((n+1)*log(n+1)-n)/n^2 - L(i);
n0 = 100; % Initial guess
n(i) = fzero(f,n0 );
However, i need to try with different values of initial guesses [0, 10, 100, 1000] etc. Someone suggets me a modified script but that is still not working,
A = readmatrix('R_mean_value_0.01.csv');
m = length(A) ;
IG = [0, 10, 100, 1000] ; % initial guess
n = length(IG) ;
nn = zeros(m,n) ;
for i = 1:n
n0 = IG(i) ;
f = @(n)((n+1)*log(n+1)-n)/n^2 - A(j);
nn(i,j) = fzero(f,n0 );
May someone suggest me any possibel solution.
Walter Roberson on 17 Mar 2022
If your initial guess is not between about -1 and about +40 then you might not get a solution.
filename = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/930814/R_mean_value_0.01%20.csv';
A = readmatrix(filename);
f = @(n)((n+1)*log(n+1)-n)/n^2;
baseeqn = f(N);
fplot(baseeqn, [-1.5 40])
minA = min(A)
maxA = max(A)
sol1 = vpasolve(baseeqn - A(1), 0.5)
fplot(baseeqn, [32 40]); hold on;