Clear Filters
Clear Filters

Operands to the logical AND (&&) and OR (||) operators must be convertible to logical scalar values. Use the ANY or ALL functions to reduce operands to logical scalar values.

5 views (last 30 days)
function [y,Err,n] = ARCTANA(x)
[rows,columns]=size(x);
y_plot=zeros(rows,columns);
err_plot=zeros(rows,columns);
n_plot=zeros(rows,columns);
for f=1:rows
for g=1:columns
v=x(f,g);
if v<=-1
N=50;
y=(-pi/2);
for k=0:N
an=((-1)^k)/((2*k+1)*(v^(2*k+1)));
y=y-an;
end
real=atan(v);
Err=abs(real-y);
n=N;
elseif -1<v & v<1
an=v;
y=an;
k=1;
while abs(an)>1E-12
an=(((-1)^k)*v^(2*k+1)/(2*k+1));
y=y+an;
k=k+1;
end
real=atan(v);
Err=abs(real-y);
n=k-1;
else
an=1/v;
y=(pi/2);
k=0;
while abs(an)>1E-12 & k<=50
an=((-1)^k)/((2*k+1)*(v^(2*k+1)));
y=y-an;
k=k+1;
end
real=atan(v);
Err=abs(real-y);
n=k;
end
y_plot(f,g)=y;
y=y_plot;
n_plot(f,g)=n;
n=n_plot
err_plot(f,g)=Err;
Err=err_plot;
end
end
This is the code I wrote
******* GRADING OUTPUT *******
Function name.......CORRECT
inputs.......CORRECT +1 points
outputs.......CORRECT +1 points
Calling function [y, Err, n] = ARCTANA(1 x 1 array)
Grading variable y........correct size +0.5 points
....correct value +0.5 points
Grading variable Err........correct size +0.5 points
....correct value +0.5 points
Grading variable n........correct size +0.5 points
....correct value +0.5 points
Calling function [y, Err, n] = ARCTANA(3 x 5 array)
Grading variable y........correct size +0.5 points
....correct value +0.5 points
Grading variable Err........correct size +0.5 points
....correct value +0.5 points
Grading variable n....Operands to the logical AND (&&) and OR (||) operators must be convertible to logical scalar values. Use the ANY or ALL functions to reduce operands to logical
scalar values.
Error in TestARCTANA
Error in TestARCTANA
Error in TestARCTANA
This is the output of the P-code and I am confused on what is wrong. If I enter a "test" array myself through the function it works just fine.

Accepted Answer

Walter Roberson
Walter Roberson on 14 Mar 2024
Moved: Walter Roberson on 14 Mar 2024
You would get this error if the grading system is expecting n to be a scalar but n is a 2D array instead.
  6 Comments
Walter Roberson
Walter Roberson on 18 Mar 2024
The grading system contains instructor-written tests for the correctness of variables. The instructor did not think of the possibility that n might not be scalar, and accidentally wrote tests that assume that it is scalar.

Sign in to comment.

More Answers (0)

Tags

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!