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

1 Ansicht (letzte 30 Tage)
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?

Antworten (1)

Torsten
Torsten am 19 Feb. 2023
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 Kommentare
Torsten
Torsten am 19 Feb. 2023
Bearbeitet: Torsten am 19 Feb. 2023
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 am 19 Feb. 2023
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 .

Melden Sie sich an, um zu kommentieren.

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by