Borrar filtros
Borrar filtros

Why is it Showing this error? Help me please.

1 visualización (últimos 30 días)
salman
salman el 14 de En. de 2024
Comentada: Walter Roberson el 14 de En. de 2024
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);

Respuestas (1)

Walter Roberson
Walter Roberson el 14 de En. de 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 comentarios
salman
salman el 14 de En. de 2024
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 el 14 de En. de 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);

Iniciar sesión para comentar.

Categorías

Más información sobre Get Started with Optimization Toolbox en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by