can someone help me create this function

Can some one create matlab code for this function? I want the answers of f from 0 to 100.
m= 0 to 5.
n= 0 to 5.
r= 0 to 5 (whole numbers only)
There is one condition : m and n and r never equal 0 at the same time. If first and second = 0 the third never equal to 0

1 件のコメント

Walter Roberson
Walter Roberson 2020 年 1 月 6 日
Our policy is that we do not close Questions that have a meaningful attempt at an Answer -- not unless the Question was abusive or violated legal constraints.

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

 採用された回答

Image Analyst
Image Analyst 2020 年 1 月 5 日
編集済み: Image Analyst 2020 年 1 月 5 日

1 投票

Did you try the super-obvious brute force method of a triple for loop with an "if" test?
c = 340;
Lx = 7.85;
Ly = 6.25;
h = 4.95;
f = zeros(6, 6, 6);
for m = 0 : 5
for n = 0 : 5
for r = 0 : 5
if m==0 && n==0 && r==0
% Don't allow all 3 to be zero at the same time.
continue;
end
t = sqrt((m/Lx)^2 + (n/Ly)^2 + (r/h)^2);
% Assign t to f if t is in the range 0-100.
if t >= 0 && t <= 100
f(m+1, n+1, r+1) = t;
end
end
end
end
fprintf('Done!\n');
Otherwise you could vectorize it with meshgrid().
1.JPG

2 件のコメント

toufik mec
toufik mec 2020 年 1 月 5 日
the anwser is something like this
Image Analyst
Image Analyst 2020 年 1 月 5 日
As long as it's not homework (because you can't turn in my work pretending it's your own), you can use this code:
c = 340;
Lx = 7.85;
Ly = 6.25;
h = 4.95;
f = zeros(6*6*6, 4);
row = 1;
for m = 0 : 5
for n = 0 : 5
for r = 0 : 5
temp = (c/2) * sqrt((m/Lx)^2 + (n/Ly)^2 + (r/h)^2);
if m+n+r >= 1 && temp <= 100
f(row, :) = [m, n, r, temp];
row = row + 1;
end
end
end
end
% Crop to only however many we used.
f = f(1:row-1, :);
% Sort on column 4
f = sortrows(f, 4);
% Print out all the rows.
fprintf('m n r f(m,n,r)\n-------------\n');
for row = 1 : size(f, 1)
fprintf('%d %d %d %.1f\n', ...
f(row, 1), f(row, 2), f(row, 3), f(row, 4));
end
fprintf('Done!\n');
It will give the table shown in your image.

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

その他の回答 (2 件)

David Hill
David Hill 2020 年 1 月 5 日

1 投票

count=0;
for m=0:5
for n=0:5
for r=0:5
if r+m+n==0
break;
end
count=count+1;
f(count)=170*sqrt(m^2/61.6225 + n^2/39.0625 + r^2/24.5025);
end
end
end
end

1 件のコメント

toufik mec
toufik mec 2020 年 1 月 5 日
f between 0-100 only how to limit that and if u can give me the answers with table like mentioned above and ty

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

David Hill
David Hill 2020 年 1 月 5 日

0 投票

count=0;
for m=0:5
for n=0:5
for r=0:5
if r+m+n==0
continue;
end
t=170*sqrt(m^2/61.6225 + n^2/39.0625 + r^2/24.5025);
if t >= 0 && t <= 100
count=count+1;
f(count,:)=[m,n,r,t];
end
end
end
end

カテゴリ

ヘルプ センター および File ExchangeData Type Identification についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by