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

Stephen23
Stephen23 2017년 5월 30일
@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 2017년 6월 5일
(Answers Dev) Restored edit

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

답변 (1개)

Andrei Bobrov
Andrei Bobrov 2017년 5월 21일
편집: Andrei Bobrov 2017년 5월 22일

2 개 추천

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

jourdan joyner
jourdan joyner 2017년 5월 21일
편집: jourdan joyner 2017년 5월 21일
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?

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

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

태그

질문:

2017년 5월 21일

댓글:

2017년 6월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by