0% found this document useful (0 votes)
58 views14 pages

L01 - T01 - ODE Warmup Problem

This document presents the analytical and finite difference solutions to the one-dimensional heat equation for a heated rod. It describes the problem of a rod with specified temperatures at the boundaries being heated along its length. It then shows the analytical solution, defines the finite difference formulation, and provides Matlab code to numerically solve the problem for a range of grid sizes. The code calculates the numerical solution, error compared to exact solution, and plots the results to determine the best grid size for accuracy.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views14 pages

L01 - T01 - ODE Warmup Problem

This document presents the analytical and finite difference solutions to the one-dimensional heat equation for a heated rod. It describes the problem of a rod with specified temperatures at the boundaries being heated along its length. It then shows the analytical solution, defines the finite difference formulation, and provides Matlab code to numerically solve the problem for a range of grid sizes. The code calculates the numerical solution, error compared to exact solution, and plots the results to determine the best grid size for accuracy.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

ODE Warmup Problem

Heated Rod
Source: Appied Numerical Methods
Chapra, 3rd Edition
Heated Rod

ME 626 ADVANCED NUMERICAL METHODS 2/27/2021 2


Analytical Solution

ME 626 ADVANCED NUMERICAL METHODS 2/27/2021 3


Finite Difference Solution

ME 626 ADVANCED NUMERICAL METHODS 2/27/2021 4


Finite Difference Solution (Ex. 24.5) coefficients

L= 10 m
h’ = 0.05 m-2
T = 200 K 0 1 2 3 4 5
Ta = 300 K
Tb = 400 K
x= 2m

For node 1:

ME 626 ADVANCED NUMERICAL METHODS 2/27/2021 5


Finite Difference Solution

ME 626 ADVANCED NUMERICAL METHODS 2/27/2021 6


HW – Heated Road
› Write a computer program to generate › Submission Guides
and solve the matrix shown in example
24.5. › Submission deadline: Monday
› Find and Plot the solution for : › Send it to my email:
– x= 10/3 m [email protected]
– x= 2m
– x= 1m › Email Subject: ME626 HW1
– x= 0.5 m › Email attachments
– Exact solution
– PDF file (report file)
› Draw the error against step size at the – M File (program file)
middle (x=5m).
› What is the best step size?

ME 626 ADVANCED NUMERICAL METHODS 2/27/2021 7


Matlab\Octave Code
% ..Program Start
clc; % Clean the command window.
clear all; % Clear all previously used variables.
close all; % Close all previously used figures.
% Exact Solution
Temp = @(x) 200 +20.4671*exp(sqrt(0.05)*x)+...
79.5329*exp(-sqrt(0.05)*x);
fplot(@ (x) Temp(x),[0 ,10],'linewidth',3)
xlabel('Distance, m')
ylabel('Temperature, K')
title('Exact Solution')
ylim([280 400])
grid on

ME 626 ADVANCED NUMERICAL METHODS 2/27/2021 8


Matlab\Octave Code
% Numerical Solution
% Constant data
L=10; % Length in m
hd=0.05; % constant
Tinf=200; % ambient temp. K
Ta=300; % First BC
Tb=400; % Second BC
% Input data
n=input ("Number of Interior Nodes, n= ");
dx=L/(n-1);
% Calculating some constants −𝑇𝑖−1 + 𝑘1 𝑇𝑖 − 𝑇𝑖+1 = 𝑘2
k1=2+hd*dx^2;
k2=hd*dx^2*Tinf;

ME 626 ADVANCED NUMERICAL METHODS 2/27/2021 9


Matlab\Octave Code
% Initialize matrices
0 1 2 3 4 5
a=0;
b=0;

−𝑇𝑖−1 + 𝑘1 𝑇𝑖 − 𝑇𝑖+1 = 𝑘2
% Define the coefficients of boundary nodes
a(1,1)= k1;
a(1,2)=-1; › Apply the equation at each interior
b(1)=k2+Ta;
node
a(n,n-1)= -1;
𝑘1 −1 𝑇1 𝑘2 + 𝑇𝑎
a(n,n)= k1;
−1 𝑘1 −1 𝑇2 𝑘2
b(n)=k2+Tb; =
−1 𝑘1 −1 𝑇3 𝑘2
−1 𝑘1 𝑇4 𝑘2 + 𝑇𝑏
ME 626 ADVANCED NUMERICAL METHODS 2/27/2021 10
Matlab\Octave Code
% Define the coefficients of interior nodes
for i=2:n-1
a(i,i-1)=-1;
a(i,i)=k1;
𝑘1 −1 𝑇1 𝑘2 + 𝑇𝑎
a(i,i+1)=-1;
−1 𝑘1 −1 𝑇2 𝑘2
=
−1 𝑘1 −1 𝑇3 𝑘2
b(i)=k2;
−1 𝑘1 𝑇4 𝑘2 + 𝑇𝑏
endfor
b=b’; % Transverse b to column vector

% Solve system of algebraic equations


T=a\b;

ME 626 ADVANCED NUMERICAL METHODS 2/27/2021 11


Matlab\Octave Code
› %Print and Plot the results
› x=[0:dx:L]
› T=[Ta;T;Tb]
› Te=Temp(x)’;
› TrueError = (Te-T) /Te *100
› z=[x’, Te, T, TrueError];

ME 626 ADVANCED NUMERICAL METHODS 2/27/2021 12


Matlab\Octave Code
› %Print and Plot the results
› x=[0:dx:L];
› Te=Temp(x)’;
› n
› disp(' x Exact Numerical True Error %')
› z=[x',Te,T,(Te-T)./Te.*100];
› disp(z)
› hold on, plot(x,T,'--','LineWidth',2,'DisplayName',[num2str(dx)])
› xlabel('Distance, m')
› ylabel('Temperature, K')
› xlim([0 10]); ylim([280 400]);
› legend('Exact Solution','Numerical Solution')

ME 626 ADVANCED NUMERICAL METHODS 2/27/2021 13


Prespecified Tolerance εs

› Number of significant figures 4


› 𝜀𝑠 = 0.5 × 102−4 = 𝟎. 𝟎𝟎𝟓

dx T(5m) Et % Ea (%)

3.3333 296.4 0.54132

2 291.5 0.21741 1.7035

1 288.8 0.05739 0.9319

0.5 288.6 0.0144 0.0423

0.25 288.6 0.0036 0.0108

0.001 288.6 1.01E-05 0.0021

ME 626 ADVANCED NUMERICAL METHODS 14

You might also like