Unable to apply an if condition x^2+y^2=a^2;

1 回表示 (過去 30 日間)
Muhammad Mubashar saeed
Muhammad Mubashar saeed 2021 年 4 月 25 日
コメント済み: DGM 2021 年 4 月 25 日
I have this code and I just want to execute values of x & y with this condition
x^2+y^2=a^2;
f=2500;
Rt=30;
x=1:0.1:5;
y=1:0.1:5;
x.^2+y.2<=a.^2
D=500;
a=((3*f.*Rt*D)./4).^(1/3);
p=((3*f)./(2*pi*a.^2))*x.*y;
plot(a,p)

回答 (1 件)

DGM
DGM 2021 年 4 月 25 日
編集済み: DGM 2021 年 4 月 25 日
This is a logical test that's not being assigned to any variable. It does nothing but dump to console.
x.^2+y.2<=a.^2
You have to actually use the result for something in order for it to have any effect.
D=500;
a=((3*f.*Rt*D)./4).^(1/3); % you have to actually define a before you use it
mask=x.^2+y.^2<=a.^2; % y.2 isn't a valid expression
p=((3*f)./(2*pi*a^2))*x(mask).*y(mask);
and plotting a vector versus a scalar doesn't do anything useful
plot(p)
There are probably other errors still.
  3 件のコメント
Muhammad Mubashar saeed
Muhammad Mubashar saeed 2021 年 4 月 25 日
x^2+y^2<=a^2;
DGM
DGM 2021 年 4 月 25 日
That's what the mask is for. It selects the values that meet the condition.

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

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by