I am trying to use ndgrid to calculate values for an optimization problem. I was able to successfully use the function for my equation but I am unable to find the optimal points or retrieve data from it at all. Only thing that hasn't returned an error is trying a feather graph ( which crashed my computer). Any help is much appreciated.
n=1:20;
[nFin, d ,L ,Aw] = ndgrid(n(:).^2,.001:.001:.05,.001:.001:.05,.01:.01:.5);
%corrected length eqn
Lc = L + d./4;
%area of fin
Af = (pi./4).*d.^2;
%perimeter of fin
P = pi.*d;
% fin convection term m
m = ((h.*P)./(k.*Af)).^0.5;
q = dT.*h.*(Aw-(Af.*nFin)) + dT.*nFin.*tanh(m.*Lc).*(h.*k.*P.*Af).^0.5 ;

댓글 수: 5

Akira Agata
Akira Agata 2017년 5월 22일
The variables "h" and "k" are undefined in this program. What are these variables ?
sorry i just cut a segment of the code
%input for choosing h
hh = [8;20];
I = input ('heat transfer coefficient of 8 or 20?\n');
h = hh(floor(I/8));
%k of aluminum
k = 204;
Akira Agata
Akira Agata 2017년 5월 22일
Thank you for your answer, but next "dT" is still undefined...
Thank you for providing a hole code. Then, let me clarify what exactly you would like to find (i.e. what 'optimal point' in your question means). If you want to find the minimum point of 4-D matrix 'a', then you can do as follows:
[val, idx] = min(a(:));
[i,j,k,h] = ind2sub(size(a), idx);
Then, the minimum value and it's index can be found to a(i,j,k,h) = val.
Thank you. I am hoping to find the minimum values where q= 30, using the suggestion you give as written gives me the first value in the q matrix I tried to rewrite as
[val, idx] = min(q(:));
[nFin,d,L,Aw] = ind2sub(size(q), q>30&&q<30.1);
but there is an error due to q being vector. Is it possible to still use this line of code in this manner?

댓글을 달려면 로그인하십시오.

 채택된 답변

Akira Agata
Akira Agata 2017년 5월 22일

1 개 추천

Thank you for your clarifications!
The following code will find the minimum value of 4-D matrix 'a' where 30 < q < 30.1.
% Generate 4-D logical array indicating 30<q<30.1
idx1 = (q > 30) & (q < 30.1);
% Find a minimum value of 'a' where 30<q<30.1
[val, idx2] = min(a(idx1));
% Returns subscripts from linear index
[i,j,k,l] = ind2sub(size(idx1), find(idx1, idx2));
Then, a(i,j,k,l) is the minimum value where 'q' is 30<q<30.1.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Problem-Based Optimization Setup에 대해 자세히 알아보기

질문:

2017년 5월 22일

댓글:

2017년 5월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by