how to multiple elements in arrays together

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 Kommentare

Stephen23
Stephen23 am 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
Rena Berman am 5 Jun. 2017
(Answers Dev) Restored edit

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Andrei Bobrov
Andrei Bobrov am 21 Mai 2017
Bearbeitet: Andrei Bobrov am 22 Mai 2017

2 Stimmen

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 Kommentar

jourdan joyner
jourdan joyner am 21 Mai 2017
Bearbeitet: jourdan joyner am 21 Mai 2017
First off,thank you for replying. The solution you presented works to use each nFin by the L,d, and Aw terms. My problem is I need the code to run through the equations for each variable. For example
nFin(1),d(1),L(1),Aw(1)
nFin(1),d(1),L(1),Aw(2)
nFin(3),d(1),L(3),Aw(1)
nFin(1),d(4),L(1),Aw(6)
I have tried using the (:) notation you used but it does not run correctly. Would you be able to tell how I would do that?

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Programming finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 21 Mai 2017

Kommentiert:

am 5 Jun. 2017

Community Treasure Hunt

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

Start Hunting!

Translated by