필터 지우기
필터 지우기

Error: Operator '*' is not supported for operands of type 'function_handle'.

조회 수: 2 (최근 30일)
JingChong Ning
JingChong Ning 2023년 2월 19일
댓글: Walter Roberson 2023년 2월 19일
This is my code:
cb = 1/5.25; %reverse of aspect ratio
cla = 2*pi; %the slope of lift vs aoa
aa = 5*pi/180; % radiant value of 5 degree
N = [3 5 7]; %list of possible N value
syms a1 a2 a3 a4 a5 a6 a7
A = [a1 a2 a3 a4 a5 a6 a7]; %list of possible An
eqn = A; %list of possible equations
for i = 1:3 %3 possible N values
counter = N(i); %how many A s would there be
Acou = A(1:counter); %set up necessary storage space
anslist = Acou; %set up necessary storage space
eqncou = eqn(1:counter); %how many equation would there be
spandiv = 1/(counter+1); %split up the 90 degree by number of equations
solved = Acou; %set up necessary storage space
for j = 1:counter %number of possible angle values
theta = spandiv*j; %angle value, 1/3, 2/3, 3/3 of 90 degree etc.
temp = 0; %set up necessary storage space
sym(temp); %set up necessary storage space
for k = 1:counter %number of An
anslist(k) = A(k)*(sinpi(k*theta)+0.25*cb*cla*k*(sinpi(k*theta)/sinpi(theta))); %each of the An expression for one angle value
temp = temp + anslist(k); %summing all An expression
end
eqncou(j) = temp == 0.25*cb*cla*aa; %turn into equation
end
Asol = vpasolve(eqncou,Acou); %solve them
%
if counter == 3
solved(1) = Asol.a1;
solved(2) = Asol.a2;
solved(3) = Asol.a3;
elseif counter == 5
solved(1) = Asol.a1;
solved(2) = Asol.a2;
solved(3) = Asol.a3;
solved(4) = Asol.a4;
solved(5) = Asol.a5;
elseif counter == 7
solved(1) = Asol.a1;
solved(2) = Asol.a2;
solved(3) = Asol.a3;
solved(4) = Asol.a4;
solved(5) = Asol.a5;
solved(6) = Asol.a6;
solved(7) = Asol.a7;
end
temp = 0;
sym(temp);
for j = 1:counter
eqn1 = @(theta) solved(j)*sinpi(j*theta);
temp = @(theta) temp + eqn1;
end
clbase = temp;
cL = @(theta) 4*5.25*clbase*-0.5*sin(theta);
integral(cL,-1*pi/2,pi/2)
%}
end
The error is in the line
cL = @(theta) 4*5.25*clbase*-0.5*sin(theta);
in the form of:
Operator '*' is not supported for operands of type 'function_handle'.
Error in ae515hw1>@(theta)4*5.25*clbase*-0.5*sin(theta) (line 57)
cL = @(theta) 4*5.25*clbase*-0.5*sin(theta);
Error in integralCalc/iterateScalarValued (line 314)
fx = FUN(t);
Error in integralCalc/vadapt (line 132)
[q,errbnd] = iterateScalarValued(u,tinterval,pathlen);
Error in integralCalc (line 75)
[q,errbnd] = vadapt(@AtoBInvTransform,interval);
Error in integral (line 88)
Q = integralCalc(fun,a,b,opstruct);
Error in ae515hw1 (line 58)
integral(cL,-1*pi/2,pi/2)
Does anyone know how to resolve this?

답변 (1개)

Torsten
Torsten 2023년 2월 19일
cb = 1/5.25; %reverse of aspect ratio
cla = 2*pi; %the slope of lift vs aoa
aa = 5*pi/180; % radiant value of 5 degree
N = [3 5 7]; %list of possible N value
syms a1 a2 a3 a4 a5 a6 a7
A = [a1 a2 a3 a4 a5 a6 a7]; %list of possible An
eqn = A; %list of possible equations
format long
for i = 1:3 %3 possible N values
counter = N(i); %how many A s would there be
Acou = A(1:counter); %set up necessary storage space
anslist = Acou; %set up necessary storage space
eqncou = eqn(1:counter); %how many equation would there be
spandiv = 1/(counter+1); %split up the 90 degree by number of equations
solved = Acou; %set up necessary storage space
for j = 1:counter %number of possible angle values
theta = spandiv*j; %angle value, 1/3, 2/3, 3/3 of 90 degree etc.
temp = 0; %set up necessary storage space
sym(temp); %set up necessary storage space
for k = 1:counter %number of An
anslist(k) = A(k)*(sinpi(k*theta)+0.25*cb*cla*k*(sinpi(k*theta)/sinpi(theta))); %each of the An expression for one angle value
temp = temp + anslist(k); %summing all An expression
end
eqncou(j) = temp == 0.25*cb*cla*aa; %turn into equation
end
Asol = vpasolve(eqncou,Acou); %solve them
%
if counter == 3
solved(1) = Asol.a1;
solved(2) = Asol.a2;
solved(3) = Asol.a3;
elseif counter == 5
solved(1) = Asol.a1;
solved(2) = Asol.a2;
solved(3) = Asol.a3;
solved(4) = Asol.a4;
solved(5) = Asol.a5;
elseif counter == 7
solved(1) = Asol.a1;
solved(2) = Asol.a2;
solved(3) = Asol.a3;
solved(4) = Asol.a4;
solved(5) = Asol.a5;
solved(6) = Asol.a6;
solved(7) = Asol.a7;
end
clbase = @(theta)sum(double(solved(1:counter)).*sinpi((1:counter).*theta));
cL = @(theta)4*5.25*clbase(theta).*(-0.5)*sin(theta);
integral(cL,-1*pi/2,pi/2,'ArrayValued',true)
end
ans =
0.034892168583369
ans =
0.034816069810405
ans =
0.034856820993593
  댓글 수: 3
Torsten
Torsten 2023년 2월 19일
편집: Torsten 2023년 2월 19일
I changed
temp = 0;
sym(temp);
for j = 1:counter
eqn1 = @(theta) solved(j)*sinpi(j*theta);
temp = @(theta) temp + eqn1;
end
clbase = temp;
cL = @(theta) 4*5.25*clbase*-0.5*sin(theta);
integral(cL,-1*pi/2,pi/2)
to
clbase = @(theta)sum(double(solved(1:counter)).*sinpi((1:counter).*theta));
cL = @(theta)4*5.25*clbase(theta).*(-0.5)*sin(theta);
integral(cL,-1*pi/2,pi/2,'ArrayValued',true)
and included
format long
before the for-loop.
Walter Roberson
Walter Roberson 2023년 2월 19일
With special emphasis on changing 5.25*clbase to 5.25*clbase(theta)
By the way: if you have a number of scalar constants being multiplied and divided, it is more efficient to group them all together before any variable gets involved.
4*5.25*(-0.5) * clbase(theta).*sin(theta)
only has to do scalar multiplications for 4 and 5.25 and -0.5 no matter how large the expression clbase(theta) turns out to be. Whereas if you had (for example) 5.25*clbase(theta)*(-0.5) then the is one multiplication by 5.25 for each value in clbase(theta) and then there would be another multiplication by -0.5 for each element of the previous result -- 2*N multiplications for N = length(clbase(theta)) whereas the 5.25*(-0.5)*clbase(theta) would have 1 multiplication for the 5.25*(-0.5) and then N multiplications (one for each element) for a total of N+1 multiplications instead of 2*N .

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by