Problem 4

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

PROBLEM 4

The temperatures measured at various points inside a heated wall are given in the
following table:
Table 1
Distance from the heated surface as a 0 25 50 75 100
percentage of wall thickness(D)
Temperature o C(t) 460 400 300 140 60
a. Find α and β of a linear equation t = αD + β to approximate the table.
b. Find a, b, and c of a parabolic equation t = aD2 + bD + c to approximate the table.
c. Compare the accuracy of the approximate equations with 2-norm error.

MATLAB CODE

D=0:25:100;
t=[460,400,300,140,60];
% a) FInd alpha and beta of the linear equation
constant=lsqcurvefit(@f_line,[0,0],D,t);
alpha=constant(1);
beta=constant(2);
% b) FInd the constants a b c of the parabolic equation
cons=lsqcurvefit(@f_parab,[0,0,0],D,t);
a=cons(1);
b=cons(2);
c=cons(3);
xfit=0:.1:100;
yfit=f_line(constant,xfit);
yfit2=f_parab(cons,xfit);
figure
plot(D,t,'o');
hold on
plot(xfit,yfit,'r',xfit,yfit2,'b','linewidth',2);
xlabel('DIstance');
ylabel('Temperature');
legend('actual','linearfit','quadratic')
grid on
% c) Compare the accuracy of the approximate equations with 2-norm
error
norm=sqrt((460-yfit(1))^2+(400-yfit(251))^2+(300-yfit(501))^2+(140-
yfit(751))^2+(60-yfit(1001))^2);
norm1=sqrt((460-yfit2(1))^2+(400-yfit2(251))^2+(300-
yfit2(501))^2+(140-yfit2(751))^2+(60-yfit2(1001))^2);

1
Workspace Results
Part a
alpha =-4.24; beta=484

Part b
a= -0.0114; b=-3.0971; c= 469.7143

Part-C
2-Norm of linear model=50.1996
2-Norm of the quadratic model=42.4937

Published with MATLAB® R2017b


2
Function for line equation

function t=f_line(constant,D)
t=constant(1)*D+constant(2); % t= D*alpha+beta
end

Function for Parabola equation

function t=f_parab(cons,D)
t=D.*(cons(1)*D+cons(2))+cons(3); % t= aD^2+b*D+c
end

You might also like