exercise8.m

% Loesung von Aufgabe 8

% Wert der Temperatur
t1 = 23.1; % in Grad Celsius

% Einlesen der Messwerte
load -ascii ex8_1.dat
t_mess = ex8_1(1:2:end);
cp_mess = ex8_1(2:2:end);

% Fitfunktionen
lin = polyfit(t_mess, cp_mess, 1);
para2 = polyfit(t_mess, cp_mess, 2);
para4 = polyfit(t_mess, cp_mess, 4);

% Bestimmen des Schaetzwertes
cp1 = polyval(lin, t1)
cp2 = polyval(para2, t1)
cp4 = polyval(para4, t1)

% Plotten der Messwerte und Interpolationsfunktionen
t = 0:100;
cp_lin = polyval(lin, t);
cp_para2 = polyval(para2, t);
cp_para4 = polyval(para4, t);

% schoene Ausgabe
plot(t_mess, cp_mess, 'r*', t, cp_lin, 'b:', t, cp_para2, 'b-.', ...
     t, cp_para4, 'b-');

xmin = 0;
xmax = 100;
ymin = 4.16;
ymax = 4.24;
axis([xmin xmax ymin ymax]);

title('Spezifische Waermekapazitaet des Wassers')
xlabel('T [°C]');
ylabel('c_p [kJ/(kg K)]');
legend('Messwerte', 'Fit 1.Ordnung', 'Fit 2. Ordnung', ...
    'Fit 4. Ordnung', 'Location', 'Best')

% senkrechte Linie am gesuchten Wert dazumalen
hold on;      % kein neuer Plot
plot([t1 t1], [ymin ymax], 'g-');
hold off;

% Bild abspeichern
F = getframe(gcf);
imwrite(F.cdata, 'bild27.png');