フィルターのクリア

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.

3 ビュー (過去 30 日間)
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 件のコメント
Walter Roberson
Walter Roberson 2024 年 3 月 14 日
n_plot(f,g)=n;
n=n_plot
That is suspicious, that you are returning a 2 d array for n.
Catalytic
Catalytic 2024 年 3 月 14 日
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

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2024 年 3 月 14 日
移動済み: Walter Roberson 2024 年 3 月 14 日
You would get this error if the grading system is expecting n to be a scalar but n is a 2D array instead.
  6 件のコメント
Walter Roberson
Walter Roberson 2024 年 3 月 18 日
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 2024 年 3 月 19 日
Ok seems like something to talk to the proffesor about, thanks.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by