I missed it in my first answer ...

The variable T is growing in your inner loop. I got distracted by the i, and thought it would only grow a little bit. What is happening is that every time abs(a-b) < g, you need to allocate a new memory buffer for T that is one slot bigger than the current T. Then you need to copy the old T into the new memory buffer and finally add the new element in. This is hugely time consuming as the size of T grows.

You need to preallocate T in some way. Assuming 1 loop is speedy enough, and that you only want 1000 loops something like

C_pd = Specific_Heat(T_d,X_d);

C_pb = Specific_Heat(T_b,X_b);

e = 0.1;

f = e;

g = 0.01;

k = 0;

l = 100;

m = k;

n = l;

T = [];

for j=1:3

i = 1;

Ttemp = [];

for T_f = k:e:l

C_pf = Specific_Heat(T_f,X_f);

a = M_f*C_pf*(T_f-T_cw);

for T_o = m:f:n

b = M_d*C_pd*(T_d-T_o) + M_b*C_pb*(T_b-T_o);

if abs(a-b)<g

Ttemp(1,i) = T_f;

Ttemp(2,i) = T_o;

i=i+1;

end

end

end

T = [T, Ttemp];

k = min(T(1,:));

l = max(T(1,:));

m = min(T(2,:));

n = max(T(2,:));

e = e/10;

f = f/10;

g = g/10;

end