Unrecognized variable, want to create a list of variable
Show older comments
Hello,
I'm trying to run an optimization model but I always get the error "Unrecognized function or variable 'c1_std'.
I want to call d = (c1_std, c2_std, c3_std) to run my optimization model and find the best parameters. How should I define d to call d(1)=c1_std in my different functions?
I'm not an expert in Matlab so please excuse me if my code is quite rude.
Thank you in advance.
Paul
muL = 2000;
sigL = 200;
R1 = 1-9.92*10^-5;
R2 = 1-1.2696*10^-4;
R3 = 1-3.87*10^-6;
d = [c1_std,c2_std,c3_std];
Sr1_min = sqrt(((((1.5-1)*muL)/norminv(R1))^2)-(sigL)^2);
Sr1_max = sqrt(((((2.5-1)*muL)/norminv(R1))^2)-(sigL)^2);
Sr2_min = sqrt(((((1.5-1)*muL)/norminv(R2))^2)-(sigL)^2);
Sr2_max = sqrt(((((2.5-1)*muL)/norminv(R2))^2)-(sigL)^2);
Sr3_min = sqrt(((((1.5-1)*muL)/norminv(R3))^2)-(sigL)^2);
Sr3_max = sqrt(((((2.5-1)*muL)/norminv(R3))^2)-(sigL)^2);
sqrt((((1.5-1)*muL)/norminv(R1)^2)-(sigL)^2)
norminv(R1)
lb = [Sr1_min,Sr2_min,Sr3_min];
ub = [Sr1_max,Sr2_max,Sr3_max];
A = [];
B = [];
Aeq = [];
Beq = [];
d0 = (lb+ub)/2;
fun = @(d) parameterfun(d,muL,sigL);
const = @(d) nonlcon(d,muL,sigL);
[d,fval] = fmincon(fun,d0,A,B,Aeq,Beq,lb,ub,const);
function Rs = parameterfun(d,muL,sigL)
muL = 2000;
sigL = 200;
R1 = 1-9.92*10^-5;
R2 = 1-1.2696*10^-4;
R3 = 1-3.87*10^-6;
d = [c1_std,c2_std,c3_std];
mu_Sr1 = muL+norminv(R1)*sqrt((sigL)^2+(d(1))^2);
mu_Sr2 = muL+norminv(R2)*sqrt((sigL)^2+(d(2))^2);
mu_Sr3 = muL+norminv(R3)*sqrt((sigL)^2+(d(3))^2);
Y1_mean = muL-mu_Sr1;
Y2_mean = muL-mu_Sr2;
Y3_mean = muL-mu_Sr3;
Y1_std = sqrt((d(1))^2+(sigL)^2);
Y2_std = sqrt((d(2))^2+(sigL)^2);
Y3_std = sqrt((d(3))^2+(sigL)^2);
Y_mean = [Y1_mean Y2_mean Y3_mean];
Y_std = [(Y1_std^2) (sigL)^2 (sigL)^2; (sigL)^2 (Y2_std)^2 (sigL)^2; (sigL)^2 (sigL)^2 (Y3_std)^2];
y = zeros(size(d));
Rs = mvncdf(y, Y_mean, Y_std);
end
function [c,ceq] = nonlcon(d,muL,sigL)
muL = 2000;
sigL = 200;
R1 = 1-9.92*10^-5;
R2 = 1-1.2696*10^-4;
R3 = 1-3.87*10^-6;
d = [c1_std,c2_std,c3_std];
c(1) = ns_min(1) - ((muL+norminv(R1)*sqrt((d(1)^2)+(L_std^2)))/muL);
c(2) = ns_min(2) - ((muL+norminv(R2)*sqrt((d(2)^2)+(L_std^2)))/muL);
c(3) = ns_min(3) - ((muL+norminv(R3)*sqrt((d(3)^2)+(L_std^2)))/muL);
c(4) = ((muL+norminv(R1)*sqrt((d(1)^2)+(L_std^2)))/muL) - ns_max(1);
c(5) = ((muL+norminv(R2)*sqrt((d(2)^2)+(L_std^2)))/muL) - ns_max(2);
c(6) = ((muL+norminv(R3)*sqrt((d(3)^2)+(L_std^2)))/muL) - ns_max(3);
c(7) = c_min(1) - (c1_std/((muL+norminv(R1)*sqrt((d(1)^2)+(L_std^2)))));
c(8) = c_min(2) - (c2_std/((muL+norminv(R2)*sqrt((d(2)^2)+(L_std^2)))));
c(9) = c_min(3) - (c3_std/((muL+norminv(R3)*sqrt((d(3)^2)+(L_std^2)))));
c(10) = (c1_std/((muL+norminv(R1)*sqrt((d(1)^2)+(L_std^2))))) - c_max(1);
c(11) = (c2_std/((muL+norminv(R2)*sqrt((d(2)^2)+(L_std^2))))) - c_max(2);
c(12) = (c3_std/((muL+norminv(R3)*sqrt((d(3)^2)+(L_std^2))))) - c_max(3);
format long
c
ceq = [];
end
2 Comments
Jan
on 21 Nov 2022
In the line:
d = [c1_std,c2_std,c3_std];
neither Matlab nor the readers in the forum can guess, what c1_std, c2_std, c3_std is. What are these variables or functions? Where are they defined?
Paul AGAMENNONE
on 21 Nov 2022
Edited: Paul AGAMENNONE
on 21 Nov 2022
Accepted Answer
More Answers (0)
Categories
Find more on Classical Control Design 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!