Why is it Showing this error? Help me please.
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
This is the coding:
cl=load("clnaca0018.mat","cl");
cd=load("cdnaca0018.mat","cd");
% Objective function for power coefficient optimization
objectiveFunction = @(x)((cl)*cosd(x(2))+((cd)*sind(x(2)))*x(1));
% Initial guess
x0 = [10, 4];
% lower&upper bounds
lb = [0, 2];
ub = [15, 8];
A=[];
b=[];
Aeq=[];
beq=[];
% Perform optimization
x = fmincon(objectiveFunction,x0,A,b,Aeq,beq,lb,ub);
% Extract optimized parameters
optimizedTSR = x(1);
optimizedtwistAngle = x(2:end);
% Display the optimized parameters
disp('Optimized Parameters:');
disp(['Optimized Tip-Speed Ratio: ', num2str(x(1))]);
disp(['Optimized Blade Twist Angle: ', num2str(x(2))]);
This is the error:
Operator '*' is not supported for operands of type 'struct'.
Error in code1>@(x)((cl)*cosd(x(2))+((cd)*sind(x(2)))*x(1)) (line 5)
objectiveFunction = @(x)((cl)*cosd(x(2))+((cd)*sind(x(2)))*x(1));
Error in fmincon (line 563)
initVals.f = feval(funfcn{3},X,varargin{:});
Error in code1 (line 19)
x = fmincon(objectiveFunction,x0,A,b,Aeq,beq,lb,ub);
0 commentaires
Réponses (1)
Walter Roberson
le 14 Jan 2024
Change
cl=load("clnaca0018.mat","cl");
cd=load("cdnaca0018.mat","cd");
to
cl=load("clnaca0018.mat","cl");
cd=load("cdnaca0018.mat","cd");
cl = cl.cl;
cd = cd.cd;
2 commentaires
Walter Roberson
le 14 Jan 2024
That is to be expected if either you cl or your cd are non-scalar.
You could try
objectiveFunction = @(x)sum(((cl)*cosd(x(2))+((cd)*sind(x(2)))*x(1)).^2);
Voir également
Catégories
En savoir plus sur Get Started with Optimization Toolbox dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!