How can I solve different equations that depend on different changing values?

I'm trying to solve multiple equations, some depend on others. In this case s, A_t, and n_o depend on N. N should be changing in intervals of 1 from 3-10, which I did a FOR loop as n=3:10. Also, t depends on s which changes depending on the N and other equations depend on t. I'm not getting the right answers which I know because I solved the problem by hand and compared it with other person (who solved it using Python). I'm trying to plot q_f vs N, T_b vs N but I can't do so because I'm not getting the correct values.
I'm stuck and I don't know where I made a mistake.Thank you!!!
w = 0.02; % Width of Chip, in meters
lst = zeros(1, 8);
apx = zeros(1, 8);
dtr = zeros(1,8);
fgh = zeros(1,8);
for n = 3:10
i = n - 2;
[x, y, z, b] = example_fun(n, w);
lst(i) = x;
apx(i) = y;
dtr(i) = z;
fgh(i) = b;
end
disp(lst);
disp(apx);
disp(dtr);
disp(fgh);
function [q_f, q_c, T_b, T_tip] = example_fun(N, w)
k = 180; % W/(m*K)
Lb = 0.003; % Base thickness, in meters
Lf = 0.012; % Fin length, in meters
T_infinity = 20; % degree C
T_chip = 85; % degree C
h = 100; % Convection coefficient W/(m^2*K)
A_b = w^2; % Area of Base
Rt_cont = 0.00002/(A_b); % Contact Resistance (K/W)
s = (w + 2)/N; % Spacing between Fins
t = s - 2; % Thickeness of Fins
P = 2*w + 2*t; % Perimeter of Fin, in meters
A_f = 2*w*Lf; % Area of Fin, in meters
A_t = N*A_f + (w^2) - (N*w*t); % Total Area
A_c = w*t; % Cross sectional Area
Rt_cond = Lb/(k*A_b); % Conduction Resistance (K/W)
m = sqrt((h*P)/(k*A_c));
n_f = tanh(m*Lf)/(m*Lf); % Fin Efficiency
n_o = 1-((N*A_f)*(1-n_f))/(A_t); % Overrall Efficiency
Rt_f = 1/(n_o*h*A_t); % Fin Resistance
Req = Rt_cont + Rt_cond + Rt_f; % Total Resistance
q_c = (T_chip - T_infinity)/Req; % Heat Transfer Rate of Chip
T_b = T_infinity + (q_c*Rt_f); % Temperature at the base, degrees C
T_tip = T_infinity + ((T_b - T_infinity)*(1/(cosh(m*Lf)))); % Temperature at the Tip
M = sqrt(h*P*k*A_c)*(T_b*T_infinity)*tanh(m*Lf);
q_f = M*tanh(m*Lf); % Heat Transfer Rate of Fin
end

Answers (1)

As far as plotting them, this seems to work:
w = 0.02; % Width of Chip, in meters
lst = zeros(1, 8);
apx = zeros(1, 8);
dtr = zeros(1,8);
fgh = zeros(1,8);
for n = 3:10
i = n - 2;
[x, y, z, b] = example_fun(n, w);
lst(i) = x;
apx(i) = y;
dtr(i) = z;
fgh(i) = b;
end
disp(lst);
disp(apx);
disp(dtr);
disp(fgh);
nv = 3:10;
figure
plot(nv, lst)
grid
xlabel('N')
ylabel('q_f')
figure
plot(nv, dtr)
grid
xlabel('N')
ylabel('T_b')
Experiment to get the result you want.

2 Comments

This is what I had first but I'm stuck. An error pops up (Error using / Matrix dimensions must agree) in line 10 where I have s = (w+2)/N. So I tried the loop, I think I did something wrong with the loop because the answers are wrong compared to the actual.
w = 0.02;
k = 180; % W/(m*K)
Lb = 0.003; % Base thickness, in meters
Lf = 0.012; % Fin length, in meters
T_infinity = 20; % degree C
T_chip = 85; % degree C
A_b = w^2; % Area of Base
Rt_cont = 0.00002/(A_b); % Contact Resistance (K/W)
N = [3,4,5,6,7,8,9,10];
s = (w + 2)/N; % Spacing between Fins
t = s - 2; % Thickeness of Fins
P = 2*w + 2*t; % Perimeter of Fin, in meters
A_f = 2*w*Lf; % Area of Fin, in meters
A_t = N*A_f + (w^2) - (N*w*t); % Total Area
A_c = w*t; % Cross sectional Area
Rt_cond = Lb/(k*A_b); % Conduction Resistance (K/W)
m = sqrt((h*P)/(k*A_c))
n_f = tanh(m*Lf)/(m*Lf); % Fin Efficiency
n_o = 1-((N*A_f)*(1-n_f))/(A_t); % Overrall Efficiency
Rt_f = 1/(n_o*h*A_t); % Fin Resistance
Req = Rt_cont + Rt_cond + Rt_f; % Total Resistance
q_c = (T_chip - T_infinity)/Req; %
T_b = T_infinity + (q_c*Rt_f);
T_tip = T_infinity + ((T_b - T_infinity)*(1/(cosh(m*Lf))));
M = sqrt(h*P*k*A_c)*(T_b*T_infinity)*tanh(m*Lf);
q_f = M*tanh(m*Lf);
You need to do element-wise multiplication and division (exponentiation may also be required, however you do not do any exponentiation here). That uses the ‘dot operator’, so .* instead of *, ./ instead of /, and .^ instead of ^.
This works:
h = 1;
w = 0.02;
k = 180; % W/(m*K)
Lb = 0.003; % Base thickness, in meters
Lf = 0.012; % Fin length, in meters
T_infinity = 20; % degree C
T_chip = 85; % degree C
A_b = w^2; % Area of Base
Rt_cont = 0.00002/(A_b); % Contact Resistance (K/W)
N = [3,4,5,6,7,8,9,10];
s = (w + 2)./N; % Spacing between Fins
t = s - 2; % Thickeness of Fins
P = 2*w + 2*t; % Perimeter of Fin, in meters
A_f = 2*w*Lf; % Area of Fin, in meters
A_t = N*A_f + (w^2) - (N*w.*t); % Total Area
A_c = w*t; % Cross sectional Area
Rt_cond = Lb/(k*A_b); % Conduction Resistance (K/W)
m = sqrt((h*P)./(k*A_c));
n_f = tanh(m*Lf)./(m*Lf); % Fin Efficiency
n_o = 1-((N*A_f).*(1-n_f))./(A_t); % Overrall Efficiency
Rt_f = 1./(n_o*h.*A_t); % Fin Resistance
Req = Rt_cont + Rt_cond + Rt_f; % Total Resistance
q_c = (T_chip - T_infinity)./Req; %
T_b = T_infinity + (q_c.*Rt_f);
T_tip = T_infinity + ((T_b - T_infinity).*(1./(cosh(m*Lf))));
M = sqrt(h*P*k.*A_c).*(T_b*T_infinity).*tanh(
m*Lf);
q_f = M.*tanh(m*Lf);
You did not supply a value fo ‘h’, so I created one.
See the documentation on Array vs. Matrix Operations (link) for an extended discussion.

This question is closed.

Asked:

on 28 Feb 2019

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!