MATLAB: Want to vary initial condition in 2nd order ODE solver. Thought to use a loop, but running into complications with dsolve

dsolveloopode

I'm trying to vary the k variable which appears in the 2nd order ODE and the 2nd initial condition. I thought to make a for loop of k and output a solves for the distribution at each k.
Here's what I have:
%Given
L = 5/100;
T_w = 20+273.15;
h = 150;
T_inf = 50+273.15;
k =1;
q_sh = 2.5*.001;
d = 0.5*.001;
A_c = pi()*.25*d^2;
P=pi()*d;
%2nd order ODE solution to part b
syms T(x)
DT = diff(T);
ode = diff(T,x,2)== ((h*P)./(k*A_c))*(T(x) - T_inf);
for k=1:1:10
cond1 = T(0) == T_w;
cond2 = DT(L) ==q_sh./(k*A_c);
conds = [cond1 cond2];
Tsol(x,k) = dsolve(ode,conds);
y = double(Tsol(x) - 273.15) ;
end
Thanks,

Best Answer

I tried bvp4c. Didn't see (cond2 = DT(L) ==q_sh./(k*A_c))
%2nd order ODE solution to part b
cla
hold on
cm = jet(10);
for k=1:1:10
F = @(x,T) [ T(2); h*P/(k*A_c)*(T(1) - T_inf) ]; % ode function
bc = @(Ta,Tb) [ Ta(1)-T_w; Tb(2)-q_sh/(k*A_c) ]; % boundary conditions
solinit = bvpinit(linspace(0,L),[1 1]);
sol = bvp4c(F,bc,solinit);
plot(sol.x,sol.y(1,:),'color',cm(k,:))
end
hold off
str = sprintf('k%d ',1:10);
strsplit(str)
legend(strsplit(str))
result