ode45 script not changing initial values (for y) in a plot
Mostrar comentarios más antiguos
I been attempting to graph a system of diff. equations for some time now. I finally got the plots to work, but the initial values are not changing so the graphs are flat.
%create function scripts in separate .m files:
function D = Dtemp(T)
D = (.00000973/298.15^1.75)*T^1.75
function n = Ntemp(T)
n = Ptemp(T)/(0.0138*T)
function p = Ptemp(T)
p=10^(3.93068-(1337.716/(T-82.648)))*(10^5)
%Create the .m file for the Diff. EQ:
function dy = odefun(t,y)
dy = zeros(2,1)
dy(1) = -Dtemp(y(2))*1.21e-25*(Ntemp(y(2))/y(1)*948)
dy(2) = 3*5.78e5*((-Dtemp(y(2))*1.21e-25*(Ntemp(y(2))/y(1)*948))/2000.68*y(1)) + (3*(0.0454/2000.68*y(1))*((573.15-y(2))/948*y(1)))
%Open a new script and run the DE, attempting to plot:
[t,y] = ode45(@odefun,[0 .3869],[1e-6; 298.15])
plot(t,y(:,1),'-o')
figure
plot(t,y(:,2),'-o')
Results:
t =
0
0.0097
0.0193
0.0290
0.0387
0.0484
0.0580
0.0677
0.0774
0.0871
0.0967
0.1064
0.1161
y =
0.0000 298.1500
0.0000 298.1500
0.0000 298.1500
0.0000 298.1500
0.0000 298.1500
0.0000 298.1500
0.0000 298.1500
0.0000 298.1500
0.0000 298.1500
0.0000 298.1500
0.0000 298.1500
0.0000 298.1500
0.0000 298.1500
0.0000 298.1500
0.0000 298.1500
0.0000 298.1500
0.0000 298.1500
0.0000 298.1500
0.0000 298.1500
As you can see my t values are changing, but the y-arrays are not. I'm not sure what the issue is Here. Any help would be much appreciated!
Respuesta aceptada
Más respuestas (1)
Steven Lord
el 19 de Abr. de 2017
The elements of the y array are changing. They're just changing by a very, very small amount. Change the display formatting:
format longg
and evaluate your odefun for t = 0 and y = your initial conditions.
dy = odefun(0, [1e-6; 298.15]);
The elements of dy are not 0 but they are very, very small. The factors of 1.21e-25 in the lines of code that compute the elements of dy and the constant roughly equal to 4.5e-10 in your Dtemp function contribute to making the elements of dy so small.
1 comentario
Ryan Compton
el 20 de Abr. de 2017
Categorías
Más información sobre Mathematics en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!