How do I use the random function in Fsolve Matlab?

Hello everyone,
In the following codes, I am trying to determine the variable x that lets beta equal target beta. This does not work for me when I use fsolve. Could anyone please take a look at it and help me with that?
Thank you so much!
% example
clear
clc
% define values
n = 1e4;
target_beta = 2;
x = 2; % predefine x
% parameters
Mean_R = 2000 ; %mean
CoV_R = 0.1;%coefficient of variation
Std_R = Mean_R * CoV_R;
% Monte Carlo Simulation
Ri = Mean_R + Std_R .* norminv(rand(n, 1));
Mean_Q = x * 1100; % Determine which variable, x, will let the beta = target beta
CoV_Q = 0.18;
Std_Q = Mean_Q * CoV_Q;
Qi = Mean_Q + Std_Q .* norminv(rand(n, 1)); % simuate the Q term
g = Ri - Qi; % limit state function g = R - Q
m = find(g < 0); % count the number of failure cases
f = length(m); % find the failure cases number in the g = R-Q vector
pr_failure = f / n; % probability of failure
beta = norminv(1 - pr_failure); %Calculate the reliability index beta
% fsolve
alpha = fsolve(@(x) (beta-target_beta),2)

 Respuesta aceptada

Torsten
Torsten el 22 de Mzo. de 2022
This might help to get beta as a function of x:
X = (0*2000/1100:0.1:2000/1100+10).';
n = 1e4;
trials = 1e3;
beta = zeros(numel(X),1);
Pr_failure = zeros(numel(X),1);
for j=1:numel(X)
pr_failure = zeros(trials,1);
x = X(j);
for i = 1:trials
RAND = rand(n,2);
% parameters
Mean_R = 2000 ; %mean
CoV_R = 0.1;%coefficient of variation
Std_R = Mean_R * CoV_R;
% Monte Carlo Simulation
Ri = Mean_R + Std_R .* norminv(RAND(:,1));
Mean_Q = x * 1100; % Determine which variable, x, will let the beta = target beta
CoV_Q = 0.18;
Std_Q = Mean_Q * CoV_Q;
Qi = Mean_Q + Std_Q .* norminv(RAND(:,2)); % simuate the Q term
g = Ri - Qi; % limit state function g = R - Q
m = find(g < 0); % count the number of failure cases
f = length(m); % find the failure cases number in the g = R-Q vector
pr_failure(i) = f / n; % probability of failure
end
pr_failure = mean(pr_failure);
pr_failure = max(eps,pr_failure);
beta(j) = norminv(1 - pr_failure); %Calculate the reliability index beta
Pr_failure(j) = pr_failure;
end
figure(1)
plot(X,beta)
figure(2)
plot(X,Pr_failure)

4 comentarios

Bowen Yang
Bowen Yang el 26 de Mzo. de 2022
Thank you! It seems that the rand function can't be used in the fsolver.
The visualization is still useful, though.
I appreciate it.
fsolve and fzero and the least squared routines and all of the optimization routines and all of the ode and pde routines, all require that the function always returns the same results for the same values within any one run of the solver or optimizer.
fsolve and fzero and the least squared routines and most of the optimization routines and all of the ode and pde routines, require that the functions are strictly continuous with strictly continuous first derivatives, and many also require strictly continuous second derivatives as well.
ga() and gamultiobj() do not require continuity. I would need to recheck for patternsearch() and simannealbnd() and particleswarm()
These requirements are not identical with saying that you cannot use random number generation in the function. For example if you used the first model parameter as the seed for the random number generator then that could potentially satisfy the reproducibility requirements but (probably) not continuity.
Are you sure about
beta(j) = norminv(1 - pr_failure);
?
I only know
pr_failure = normcdf(-beta)
thus
beta(j) = - norminv(pr_failure)
Torsten
Torsten el 26 de Mzo. de 2022
I was hoping fsolve could be used if the number of trials was big enough to stabilize the distribution for pr_failure (and thus could return stable values to fsolve), but I was not successful. The precision needed to calculate the derivatives in fsolve is too high.

Iniciar sesión para comentar.

Más respuestas (1)

Priyanka Kondapalli
Priyanka Kondapalli el 22 de Mzo. de 2022
Editada: Priyanka Kondapalli el 24 de Mzo. de 2022
Hi,
I do not see any issue with the code provided by you.However, recheck the equation. Please refer to the link below which provides more details on how to use Fsolve.

Categorías

Más información sobre Linear Programming and Mixed-Integer Linear Programming en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 17 de Mzo. de 2022

Comentada:

el 26 de Mzo. de 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by