Why is it Showing this error? Help me please.

1 次查看(过去 30 天)
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);

回答(1 个)

Walter Roberson
Walter Roberson 2024-1-14
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 个评论
salman
salman 2024-1-14
this error shown
Error using fmincon
Supplied objective function must return a scalar value.
Error in code1 (line 20)
x = fmincon(objectiveFunction,x0,A,b,Aeq,beq,lb,ub);
Walter Roberson
Walter Roberson 2024-1-14
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);

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Get Started with Optimization Toolbox 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by