P22_1 - 0 0 0 1 -2.15 1 0 0 0; 0 0 0 0 1 -2.15 1 0 0; 0 0 0...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
function P22_1 f xspan = [0:1:10]; x T0 = 240; T10 = 150; T z0 = -50; z y0 = [T0; z0]; y [x,y] = ode45(@heat, xspan, y0); [ x1 = x(:,1); x T1 = y(:,1); T zguess1 = z0; Tguess1 = T1(end,1); T z0 = -150; z y0 = [T0; z0]; y [x,y] = ode45(@heat, xspan, y0); [ x2 = x(:,1); x T2 = y(:,1); T zguess2 = z0; Tguess2 = T2(end,1); T %linearly interpolate to get correct value of z0 that will make T(10) = 150 % slope = (zguess2 - zguess1)/(Tguess2 - Tguess1); s z0 = zguess1 + slope*(T10-Tguess1); z y0 = [T0; z0]; y [x,y] = ode45(@heat, xspan, y0); [ x3 = x(:,1); x T3 = y(:,1); T zguess3 = z0; Tguess3 = T3(end,1); T %Part C------------------------------------------------------------------ %
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
A = [-2.15 1 0 0 0 0 0 0 0; 1 -2.15 1 0 0 0 0 0 0; 0 1 -2.15 1 0 0 0 0 0; 0 0 1 -2.15 1 0 0 0 0;
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 0 0 0 1 -2.15 1 0 0 0; 0 0 0 0 1 -2.15 1 0 0; 0 0 0 0 0 1 -2.15 1 0 0 0 0 0 0 0 1 -2.15 1; 0 0 0 0 0 0 0 1 -2.15;]; b = [-240; 0; 0; 0; 0; 0; 0; 0; -150;]; b T = A\b; T Tnew = [240; T(:,1); 150]; T x = (0:1:10)'; x fprintf('part b\n') fprintf(' x T\n') for r = 1:length(x3) fprintf('%6.4f %8.4f\n', x3(r,1), T3(r,1)) end e %plot(x1,T1, '--', x2,T2, '--', x3,T3, x3, T3, 'o') % fprintf('\n') fprintf('part c\n') fprintf(' x T\n') for r = 1:length(Tnew) fprintf(' %d %8.4f\n', x(r,1), Tnew(r,1)) end e plot(x, Tnew, x, Tnew, '.') p function dydx = heat(x,y) f global m c k g T = y(1,1); T z = y(2,1); z dTdx = z; d dzdx = 0.15*T; d dydx = [dTdx; dzdx];...
View Full Document

Page1 / 2

P22_1 - 0 0 0 1 -2.15 1 0 0 0; 0 0 0 0 1 -2.15 1 0 0; 0 0 0...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online