how to multiple elements in arrays together
Afficher commentaires plus anciens
For a class project I have been tasked with writing a code that will tell me the optimal dimensions to disperse heat from a wall with a square number of pins. I am very new to matlab ( I am a cc transfer student and havent yet taken the matlab course at my college). My code runs but I need it to run through each dimension against another. My code runs them in parallel currently. I tried running multiple for loops to no avail. Here is the code:
%clear all
clear all; close all; clc;
%theta_w = dT
dT = 45;
%h1 and h2 for both cases
h1 = 8;
h2 = 20;
I = input ('heat transfer coefficient of 8 or 20?\n');
if (I < 9)
h=h1;
elseif (I > 9)
h=h2;
end
%k of aluminum
k = 204;
%Area of wall, diameter of fin, length of fin/corrected lengh of fin, and #
%of fins all variables
syms Aw d L Lc nFin;
for nFin = [1 4 9 16 25 36 49 64 81 100]
d = 0.001:.001:.05;
L = 0.001:.001:.05;
Aw = 0.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;
%tot convection
q = dT.*h.*(Aw-(Af.*nFin)) + dT.*nFin.*tanh(m.*Lc).*(h.*k.*P.*Af).^0.5 ;
%fin convection
b = dT.*nFin.*tanh(m.*Lc).*(h.*k.*P.*Af).^0.5;
%wall convection
a = dT.*h.*(Aw-(Af.*nFin));
T1=table(nFin);
T2=table(a,b,q);
end
I need the code to output a and b for each d vs each L vs each Aw. Any help is much appreciated.
2 commentaires
Stephen23
le 30 Mai 2017
@jourdan joyner: please do not delete your questions like that. Our volunteer efforts are open for everyone to utilize, but when you delete the question you unilaterally decide to treat us as your own personal consulting service, to be discarded at whim. It is not appreciated.
Rena Berman
le 5 Juin 2017
(Answers Dev) Restored edit
Réponses (1)
Andrei Bobrov
le 21 Mai 2017
Modifié(e) : Andrei Bobrov
le 22 Mai 2017
dT = 45;
hh = [8;20];
I = input ('heat transfer coefficient of 8 or 20?\n');
h = hh(ceil(I/9));
k = 204;
d = 0.001:.001:.05;
L = 0.001:.001:.05;
Aw = 0.01:.01:.5;
nFin = [1 4 9 16 25 36 49 64 81 100];
Lc = L + d/4;
Af = pi/4*d.^2;
P = pi*d;
m = (h*P./(k*Af)).^0.5;
b = dT*nFin(:).*tanh(m.*Lc).*(h*k*P.*Af).^0.5; % MATLAB >= R2016b
a = dT*h*(Aw-(Af.*nFin(:))); % MATLAB >= R2016b
b = nFin(:)*(dT*tanh(m.*Lc).*(h*k*P.*Af).^0.5);% MATLAB <= R2016a
a = dT*h*bsxfun(@minus,Aw,nFin(:)*Af); % MATLAB <= R2016a
ADD after jourdan's comment in my answer
d0 = 0.001:.001:.05;
L0 = 0.001:.001:.05;
Aw0 = 0.01:.01:.5;
nFin0 = [1 4 9 16 25 36 49 64 81 100];
n = numel(d0)^3*numel(nFin0);
Aw = zeros(n,1);
L = zeros(n,1);
d = zeros(n,1);
nFin = zeros(n,1);
dT = 45;
hh = [8;20];
I = input ('heat transfer coefficient of 8 or 20?\n');
h = hh(ceil(I/9));
k = 204;
[Aw(:),L(:),d(:),nFin(:)] = ndgrid(Aw0,L0,d0,nFin0);
Lc = L + d/4;
Af = pi/4*d.^2;
P = pi*d;
m = (h*P./(k*Af)).^0.5;
b = dT*nFin.*tanh(m.*Lc).*(h*k*P.*Af).^0.5;
a = dT*h*(Aw-(Af.*nFin));
1 commentaire
jourdan joyner
le 21 Mai 2017
Modifié(e) : jourdan joyner
le 21 Mai 2017
Catégories
En savoir plus sur Programming dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!