can someone help me create this function

12 次查看(过去 30 天)
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
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 个评论
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
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
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

类别

Help CenterFile Exchange 中查找有关 Data Type Identification 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by