How to use ode45 with initial conditions defined in script?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello, I am using ode45 to solve a differential equation. Here is the function file:
.m
function TempP=primary(Tp,y)
hp=13.64;
Tw=25;
mp=0.007;
Cp=1005;
TempP=-2*hp*(Tp-Tw)/(mp*Cp);
Now I have code in script: demo.m
clear all
yrange=[0:0.02:0.9];
Tp=40;
[Tp,y]=ode45(@primary,yrange,Tp);
figure(1)
plot(Tp,y)
ylabel('Tp (deg C)')
xlabel ('Y (m)')
If you can notice, the variables hp,Tw,mp,Cp are defined in primary.m but what I want is, to define in them in demo.m This will help me to control the initial conditions when I have such more function .m files. Is that possible?
0 comentarios
Respuestas (2)
Star Strider
el 17 de Sept. de 2016
You can easily pass your parameters to ‘primary’ from ‘demo’:
function TempP=primary(Tp,y,hp,Tw,mp,Cp)
TempP=-2*hp*(Tp-Tw)/(mp*Cp);
end
hp=13.64;
Tw=25;
mp=0.007;
Cp=1005;
yrange=[0:0.02:0.9];
Tp0=40;
[Tp,y]=ode45(@(Tp,y) primary(Tp,y,hp,Tw,mp,Cp),yrange,Tp0);
figure(1)
plot(Tp,y)
ylabel('Tp (deg C)')
xlabel ('Y (m)')
0 comentarios
Ver también
Categorías
Más información sobre Ordinary Differential Equations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!