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 Ansichten (letzte 30 Tage)
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.
  2 Kommentare
Walter Roberson
Walter Roberson am 14 Mär. 2024
n_plot(f,g)=n;
n=n_plot
That is suspicious, that you are returning a 2 d array for n.
Catalytic
Catalytic am 14 Mär. 2024
I highly recommend against "f" and "g" as symbols for loop indices. It is terribly unreadable to others -
for f=1:rows
for g=1:columns

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 14 Mär. 2024
Verschoben: Walter Roberson am 14 Mär. 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 Kommentare
Walter Roberson
Walter Roberson am 18 Mär. 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.
Sal
Sal am 19 Mär. 2024
Ok seems like something to talk to the proffesor about, thanks.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Produkte


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by