%Aufgabe 1a) 

%dU=0 
%dQ=dW=pdV=pVpunkt dt 
%Qpunkt dt = pVpunkt dt 
%Vpunkt dt = (Qpunkt/m*R*T)*V dt
%V(t)-V(0)=(Qpunkt/m*R*T)*Integral(0 bis t )(V(t')dt')

%Aufgabe 1b)

clear all;
global R cv m mapunkt cp T0 Heizleistung V0 P0 V t 
R=287.058;
cv=718.0;
V0=0.001;
Heizleistung=1;
T0=293.15;
P0=100000;
mapunkt=0.01;
cp=1005.2;


 m=(P0*V0)/(R*T0);

 Tsim=200;

 simulation_opt= simset('solver','ode5','FixedStep',1e-3);
 sim('isotherm_mod',Tsim,simulation_opt);

%Aufgabe 1c) 
%Die Funktion fällt exponentiell 

figure(1);
plot(t,V,'--,r');
hold on
grid on
xlabel 'Zeit/s';
ylabel 'Volumen/dm^3';
title Isotherme Zustansänderung;
hold off

%Aufgabe 1d)

figure(2);
plot(P,'-,y');
hold on
grid on
xlabel 'Zeit/s';
ylabel 'Druck/Pa';
title Druckverlauf;
hold off

%Aufgabe 1e)

figure(3);
plot(P,V);
hold on
grid on 
xlabel 'Druck in Pa';
ylabel 'Volumen in dm^3';
title P-V- Diagramm;
hold off

%Aufgabe 1f)

%dQ=dW=pdV=mRT*(dV/v)
%Q=m*R*T*ln(V/V0)

%Aufgabe 1g) 


T2=293.15;
p02=100000;
R2=287.058;

Tsim=60;
simulation_opt=simset('solver','ode5','FixedStep',1e-3);
sim('isotherm2_mod',Tsim,simulation_opt);

figure(4);
plot(t,heizleistungzwei,'.,g');
hold on
grid on
xlabel('Zeit in s');
ylabel('Heizleistung in W');
title('Heizleistung');
hold off

function x=Volumen(h)
global m R T0 Heizleistung V0

x=(Heizleistung/(m*R*T0))*(h(1)+V0); 

end

function y=Druck(u)
global m R T 

y=((m*R*T)/u(1))/100;

end

function z=heizleistungzwei(k)
global m R Tsim

heizleistungzwei=(m*R*T*(log((k(1)/V0))));

end
