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

Solution Interpolation & Curvefitting

Q1.
c)
clear all;
clf;
M = [0.2 0.4 0.6 0.8 1];
r = [1.05 1.1 1.3 1.55 1.9];
a = polyfit(M,r,4);
x = linspace(0,1);
y = polyval(a,x);
plot(M,r,'ko',x,y,'k-');
xlabel('Mach number')
ylabel('r')
legend('Measured data','Polynomial fit')

Measured data
1.9 Polynomial fit

1.8

1.7

1.6

1.5
r

1.4

1.3

1.2

1.1

1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Mach number
Q2

clear all;
clf;
t = [10 15 20 25 40 50 55 60 75]; % time in minute
T = [4 20 18 50 33 48 80 60 78]; % tensile strength in MPa
n = length(t); % number of data
tt = t.*t;
tT = t.*T;
sum_t = sum(t);
sum_T = sum(T);
sum_tt = sum(tt);
sum_tT = sum(tT);
mean_t = mean(t);
mean_T = mean(T);
a1 = (n*sum_tT - sum_t*sum_T)/(n*sum_tt - sum_t*sum_t);
a0 = mean_T - a1*mean_t;

x = linspace(0,100);
T_fit = a0 + a1 * x;
plot(t,T,'ko',x,T_fit,'k-')
xlabel('t (min)')
ylabel('Tensile Strength (MPa)')
legend('Measured data','Linear regression')

fprintf('The tensile strength at 30 minutes is %6.2f (MPa)


\n',a0+a1*30)

The tensile strength at 30 minutes is 34.07 (MPa)

You might also like