0% found this document useful (0 votes)
33 views4 pages

Assingment 5

This document contains code to analyze temperature profiles in a lake and calculate heat flux at the thermocline. It: 1. Interpolates temperature data at increasing depths and finds where the temperature gradient is maximum, identifying the thermocline. 2. Calculates the temperature and depth at the thermocline and estimates heat flux based on the temperature gradient. 3. Plots the temperature profile and identifies the thermocline on the graph. 4. Applies Simpson's rule and the trapezoidal rule to estimate the volumetric flow rate in a pipe, comparing the results to an analytic solution.

Uploaded by

Sara Sazna
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views4 pages

Assingment 5

This document contains code to analyze temperature profiles in a lake and calculate heat flux at the thermocline. It: 1. Interpolates temperature data at increasing depths and finds where the temperature gradient is maximum, identifying the thermocline. 2. Calculates the temperature and depth at the thermocline and estimates heat flux based on the temperature gradient. 3. Plots the temperature profile and identifies the thermocline on the graph. 4. Applies Simpson's rule and the trapezoidal rule to estimate the volumetric flow rate in a pipe, comparing the results to an analytic solution.

Uploaded by

Sara Sazna
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

Answer 1

t=[22.8 22.8 22.8 20.6 13.9 11.7 11.1 11.1];


d=[0 2.3 4.9 9.1 13.7 18.3 22.9 27.2];
dd=linspace(0,30,1000);
tt=spline(d,t,dd);
h=dd(2)-dd(1);
dy=gradient(tt,h);
dyy=gradient(dy,h);
[C,I]=max(abs(dy));
y=dd(I);
therm=spline(d,t,y);
format long
J=0.02*100*C;
fprintf('depth at thermocline in metres from lake surface=')
disp(y)
fprintf('Temperature at thermocline in degree Celsius =')
disp(therm)
fprintf('Heatflux at thermocline in Joules per second=',J)
disp(J)
subplot(211)
plot(d,t,'ob',dd,tt,'-k')
hold on
plot(y,therm,'gs','MarkerFaceColor','g')
xlabel('Depth from surface(m)');
ylabel('Temperature(degree Celsius)');
title('Temperature vs. Depth Graph','FontSize',15)
legend('real points','interpolated points','Thermocline')
subplot(212)
plot(dd,dy,'-',dd,dyy,'--')
hold on
plot(dd,0,'-k','LineWidth',26)
xlabel('Depth from surface(m)');
ylabel('(dT/dz) / (d2T/dz2)');
title('(dT/dz) / (d2T/dz2) vs. Depth Graph','FontSize',15)
legend('dT/dz','d2T/dz2','Location','SouthEast')
grid on

Output:

depth at thermocline in metres from lake surface= 11.351351351351351

Temperature at thermocline in degree Celsius = 17.305548886035709

Heatflux at thermocline in Joules per second= 3.228109213052583

Answer 2
function [ area] = simpson(x,y )
if rem(length(x),2)==0
error('insert odd number of points')
else
xx=linspace(min(x),max(x),length(x));
yy=spline(x,y,xx);
sum1=0;
sum2=0;
for i=2:length(xx)-1
if rem(i,2)==0
sum1=sum1+yy(i);
else

sum2=sum2+yy(i);

end
area=(yy(1)+yy(length(xx))+4*sum2+2*sum1)*(xx(2)-xx(1))/3;
end

end

end

Answer 3

x=0:200:4200;

y=[2440,2500,2500,2600,2700,2800,3000,31203120,3200,3200,3150,2950,2
600,2250,2050,1800,1600,1050,950,900,600,0];
x1=[x(1:length(x)-1)];
>> y1=[y(1:length(y)-1)];
a=simpson(x1,y1)
b=trapz(x,y)
Output:

a = 4.169092000000000e+009
b = 6.2493e+009
Answer 4
r=[0:2.5:20];
v=100*[0.914 0.89 .847 .795 .719 .543 .427 .204 0];

p=polyfit(r,v,2);
syms r1 v1;
v1=p(1)*r1^2+p(2)*r1+p(3);
f=r1*v1;
format long
Q=2*3.14*int(f,0,20);
fprintf('The analytic value (cubic cm per second is
Q1=58062.10701298701;disp(Q1)
for i=1:length(r)
q(i)=2*3.14*v(i)*r(i);
end
z=trapz(r,q);
s=simpson(r,q);
fprintf('The estimates are:
fprintf('Trapezoidal rule=');
disp(z)
fprintf('Simpsons rule=');
disp(s)
fprintf('Percentage Errors:
');
fprintf('Trapezoidal rule=');
disp(abs(z-Q1)/Q1 *100)
fprintf('Simpsons rule=');
disp(abs(s-Q1)/Q1 *100)

');

');

r2=linspace(0,20,100);
plot(r,v,'o',r2,polyval(p,r2),'-k')
xlabel('Radial axis(cm)');
ylabel('Velocity(cm/s)');
legend('real points','interpolated points')
title('velocity vs.radial axis graph','FontSize',25)

Output:
The analytic value (cubic cm per second is

5.806210701298701e+004

The estimates are:


Trapezoidal rule=

Simpsons rule=

5.710875000000000e+004

5.673456666666666e+004

Percentage Errors:
Trapezoidal rule= 1.641960758974475

Simpsons rule= 2.286414349419696

You might also like