Can anyone explain the error shown?

PolarAngle2 = [0:(1/180*pi):pi];
y = sin(PolarAngle2);
y = y';
SecondNormalizedIntensity = zeros(size(NormalizedIntensity));
for i = 1 : 1: 181
polarfun = @(PolarAngle2) 1./SecondNormalizedIntensity(i);
SecondNormalizedIntensity(i) = NormalizedIntensity(i) * y(i);
RadiantIntensity = zeros(size(SecondNormalizedIntensity));
RadiantIntensity = RadiantIntensity';
first = integral(polarfun,0,pi);
end

3 Comments

Error using integralCalc/finalInputChecks (line 515)
Output of the function must be the same size as the input. If FUN is an array-valued integrand, set the
'ArrayValued' option to true.
Error in integralCalc/iterateScalarValued (line 315)
finalInputChecks(x,fx);
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 ShortCircuitCurrentIncrease (line 92)
first = integral(polarfun,0,pi);
Thats the following error for the question above.
I would like to ask is there anything wrong with my integral function code?
PolarAngle = [0:(1/60*pi):2*pi]; %incremental of polar angle of sun rays
y = sin(PolarAngle);
y = y';
SecondNormalizedIntensity = zeros(size(NormalizedIntensity));
RadiantIntensity = zeros(size(SecondNormalizedIntensity));
RadiantIntensity = RadiantIntensity';
for i = 1 : 1: 181
SecondNormalizedIntensity(i) = NormalizedIntensity(i) * y(i);
polarfun = @(PolarAngle) (1/SecondNormalizedIntensity);
RadiantIntensity(i) = integral(polarfun{i},-pi/2,pi/2);
end
I met with some errors
Labelled as
Cell contents reference from a non-cell array object.
Error in ShortCircuitCurrentIncrease (line 91)
RadiantIntensity(i) = integral(polarfun{i},-pi/2,pi/2);

Sign in to comment.

 Accepted Answer

polarfun = @(PolarAngle) (1/SecondNormalizedIntensity);
defines polarfun as a single function handle.
RadiantIntensity(i) = integral(polarfun{i},-pi/2,pi/2);
refers to polarfun as if it were a cell array of function handles. The {i} part should not be there.

2 Comments

After remoivng the {i}
Error using integralCalc/finalInputChecks (line 515)
Output of the function must be the same size as the input. If FUN is an array-valued integrand, set the
'ArrayValued' option to true.
Error in integralCalc/iterateScalarValued (line 315)
finalInputChecks(x,fx);
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 ShortCircuitCurrentIncrease (line 92)
RadiantIntensity = integral(polarfun,-pi/2,pi/2);
PolarAngle2 = [0:(1/180)*pi:pi];
y = sin(PolarAngle2);
y = y';
SecondNormalizedIntensity = zeros(size(NormalizedIntensity));
RadiantIntensity = zeros(size(SecondNormalizedIntensity));
RadiantIntensity = RadiantIntensity';
for i = 1 : 1: 181
SecondNormalizedIntensity(i) = NormalizedIntensity(i) * y(i);
polarfun = @(PolarAngle) (1/SecondNormalizedIntensity);
RadiantIntensity(i) = integral(polarfun,-pi/2,pi/2);
end
Error shown as
Error using integralCalc/finalInputChecks (line 515) Output of the function must be the same size as the input. If FUN is an array-valued integrand, set the 'ArrayValued' option to true.
Error in integralCalc/iterateScalarValued (line 315) finalInputChecks(x,fx);
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 ShortCircuitCurrentIncrease (line 92) RadiantIntensity = integral(polarfun,-pi/2,pi/2);

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!