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

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
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 Exchange에서 Data Type Identification에 대해 자세히 알아보기

질문:

2020년 1월 5일

댓글:

2020년 1월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by