In the following code I am trying to solve the power law model.
I have only one known value for k and three known values for E. Thus I am guessing the lower and upper bound values of k.
I would like to solve the power law model parameters and validate them by ensuring that the difference between the known k value and the k value obtained from the power law at the corresponding E value is 0. Currently it is 0.002 and I think by implementing a code similar to that of Excel solver to set the difference to zero by changing my guesses of k would solve this problem.
Thus could someone please assist me in correcting my code/adding code to change the guessed values of k to ensure the difference at the end is 0
% ------------------ Power Law Model Analysis ------------------ %
E1 = Sheet.("ED (W/m3)"); % Independent variable (known)
% Extract the first three values from column E1
E = E1(1:3);
% Known k values for corresponding E (provided or previously calculated)
% Replace these with your actual k values
k = [0.005, k_zero_order, 0.009]; %
% Take the logarithm of E and k
logE = log(E);
logk = log(k);
% Perform linear regression to find alpha and log(C)
p = polyfit(logE, logk, 1);
alpha = p(1); % Slope of the fitted line, which is alpha
logC = p(2); % Intercept of the fitted line, which is log(C)
% Compute C from log(C)
C = exp(logC);
% Display results for power law constants
fprintf('Using regression analysis:n');
fprintf('Estimated power law exponent alpha: %.4fn', alpha);
fprintf('Estimated coefficient C: %.4fn', C);
% Compute k values using the estimated power law model
k_estimated = C * E.^alpha;
% Validate the model with the known k value
% You should replace the following with your actual known k value and corresponding E
known_k_value = k_zero_order; % Example known k value for validation
% Assume known E value corresponding to known k (for demonstration)
known_E_value = E(2); % Replace with actual corresponding E value if different
% Compute estimated k for the known E value
k_est_known = C * known_E_value^alpha;
% Display results for validation
fprintf('Using known k = %.4f and corresponding E = %.4f:n', known_k_value, known_E_value);
fprintf('Estimated k for known E = %.4f: %.4fn', known_E_value, k_est_known);
fprintf('Difference between estimated and known k value: %.4fn', abs(k_est_known - known_k_value));
1