extracting data from 4-D double

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 comentarios

Akira Agata
Akira Agata el 22 de Mayo de 2017
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 el 22 de Mayo de 2017
Thank you for your answer, but next "dT" is still undefined...
Akira Agata
Akira Agata el 22 de Mayo de 2017
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?

Iniciar sesión para comentar.

 Respuesta aceptada

Akira Agata
Akira Agata el 22 de Mayo de 2017
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.

Más respuestas (0)

Categorías

Preguntada:

el 22 de Mayo de 2017

Comentada:

el 22 de Mayo de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by