필터 지우기
필터 지우기

Why is it Showing this error? Help me please.

조회 수: 1 (최근 30일)
salman
salman 2024년 1월 14일
댓글: Walter Roberson 2024년 1월 14일
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