Professional Documents
Culture Documents
%Given Parameters
T_0=30+273;
T_1=100+273;
L=1;
%Total no of nodes
no_of_nodes=no_of_elements*no_of_nodes_per_element-(no_of_elements-1);
if i~=no_of_elements
vec=vec+no_of_nodes_per_element-1;
end
end
%To integrate a function using n base points, we may use a gauss palynomial
%of greatest_integer((n+1)/2).
degree=round((n+1)/2);
function integral=Newton_cotes_quadrature(fun,n)
%This function calculates integral using Newton-Cotes formula.
%input: fun=function to integrate, n=no of base points
%output: integral of the given function from -1 to 1
w(1)=1/2;
w(2)=1/2;
w(3)=1/6;
w(4)=4/6;
w(5)=1/6;
w(6)=1/8;
w(7)=3/8;
w(8)=3/8;
w(9)=1/8;
%\\
no_of_elements=no_of_elements1(2);
no_of_nodes_per_element=no_of_nodes_per_element1(2);
%total no of nodes
no_of_nodes=no_of_elements*no_of_nodes_per_element-(no_of_elements-1);
%length of an element
length_of_element=L/no_of_elements;
m=no_of_nodes;
%Analytical solution
T_theo=-x/20+2021.2157/20*log(1+x)+303;
T_theo_max=max(T_theo);
%Numerical solution
[K q T_cal]=oneD_FEM(no_of_elements, no_of_nodes_per_element, inte);
%//
%\\
% for j=1:3
% clear K q T_cal T_theo x
% no_of_elements=no_of_elements1(j);
% no_of_nodes_per_element=no_of_nodes_per_element1(j);
% %total no of nodes
% no_of_nodes=no_of_elements*no_of_nodes_per_element-(no_of_elements-1);
% %length of an element
% length_of_element=L/no_of_elements;
% m=no_of_nodes;
%
% %intialing parameters so that they won't change size after every
iteration
% x=zeros(1,no_of_nodes);
%
% %Global coordinates of each node
% for i=1:no_of_nodes
% x(i)=0+L/(m-1)*(i-1);
% end
%
% %Analytical solution
% T_theo=-x/20+2021.2157/20*log(1+x)+303;
% T_theo_max=max(T_theo);
%
% %Numerical solution
% [K q T_cal]=oneD_FEM(no_of_elements, no_of_nodes_per_element, inte);
%
% %plotting parameters
% %T_plot_cal(j,:)=T_cal;
% error(j)=100*(1/(sqrt(m)*abs(T_theo_max))).*sqrt((T_theo.'-
T_cal).'*(T_theo.'-T_cal));
%
% end
%//
%\\
% for j=1:6
% initialtime=cputime;
% clear K q T_cal T_theo x
% no_of_elements=3^j;
% no_of_nodes_per_element=3;
% %total no of nodes
% no_of_nodes=no_of_elements*no_of_nodes_per_element-(no_of_elements-1);
% m=no_of_nodes;
%
% %intialing parameters so that they won't change size after every
iteration
% x=zeros(1,no_of_nodes);
%
% %Global coordinates of each node
% for i=1:no_of_nodes
% x(i)=0+L/(m-1)*(i-1);
% end
%
% %Analytical solution
% T_theo=-x/20+2021.2157/20*log(1+x)+303;
% T_theo_max=max(T_theo);
%
% %Numerical solution
% [K q T_cal]=oneD_FEM(no_of_elements, no_of_nodes_per_element, inte);
%
% %plotting parameters
% %T_plot_cal(j,:)=T_cal;
% error(j)=100*(1/(sqrt(m)*abs(T_theo_max))).*sqrt((T_theo.'-
T_cal).'*(T_theo.'-T_cal));
% finaltime(j)=cputime-initialtime;
%
% end
%
% for i=1:6
% n(i)=3^i;
% end
% %plotting graphs
% plot(n,finaltime);
% xlabel('no of qudaratic elements');
% ylabel('cpu_{time} (s)');
%//
Temp_x=0;
for i=1:3
xeta=-2+i;
strating_note_of_that_element=3*(element_x-1)-(element_x-2);
[psi d_psi]=shape_function_n(3,xeta);
T_cal(strating_note_of_that_element+i-1)
psi(strating_note_of_that_element+i-1)
Temp_x
Temp_x=T_cal(strating_note_of_that_element+i-
1)*psi(strating_note_of_that_element+i-1)+Temp_x;
end
function [jac x]=jacobia(x_e,x_e_1,r,xeta)
%Method to calculate jacobian.
[psi d_psi]=shape_function_n(r,xeta);
jac=0;
for i=1:r
x(i)=x_e+((i-1)/(r-1))*(x_e_1-x_e);
jac=jac+x(i)*d_psi(i);
end